Linux rsync 权限问题——目标权限未正确应用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4114716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:53:40  来源:igfitidea点击:

rsync permissions question -- destination perms not properly applying

linuxdebianrsync

提问by Philip Walton

This is what I'm trying to do:

这就是我想要做的:

rsync -rvl --chmod=ug=rwX,o=rX test /var/www

and after I do it, here are the results I get:

在我这样做之后,这是我得到的结果:

drwxr-xr-x

(Actually it's drwxr-sr-x, but that's probably not important ... is it?)

(实际上是drwxr-sr-x,但这可能并不重要……是吗?)

This, obviously is not what I want. I want the group to have write permissions, but for some reason, the rsync command isn't setting them.

这,显然不是我想要的。我希望该组具有写入权限,但由于某种原因,rsync 命令没有设置它们。

Anyone have any ideas why not? Is there a mistake in my syntax? If it's helpful I'm transferring from OSX to Linux (Debian).

任何人有任何想法为什么不?我的语法有错误吗?如果有帮助,我将从 OSX 转移到 Linux (Debian)。

Update:Also, if it's helpful, when I enter umask, I get 0002. So that's not the problem.

更新:另外,如果有帮助,当我输入 umask 时,我会得到 0002。所以这不是问题。

采纳答案by SimonJ

--chmodoverrides the sendingside permissions, but if you don't specify -por --permsas well then the destination defaults are used regardless (i.e. --chmodis ignored).

--chmod覆盖发送方的权限,但如果您没有指定-por--perms则无论如何都会使用目标默认值(即被--chmod忽略)。

From man 1 rsync:

来自man 1 rsync

--chmod

This option tells rsync to apply one or more comma-separated "chmod" strings to the permission of the files in the transfer. The resulting value is treated as though it was the permissions that the sending side supplied for the file, which means that this option can seem to have no effect on existing files if --perms is not enabled.

--chmod

此选项告诉 rsync 将一个或多个逗号分隔的“chmod”字符串应用于传输中文件的权限。结果值被视为发送方为文件提供的权限,这意味着如果 --perms 未启用此选项似乎对现有文件没有影响

回答by Ben Hymanson

I think you need to add --perms(aka -p). Quoting from the manpage:

我认为您需要添加--perms(又名-p)。引用手册页:

When this option is off, permissions are set as follows:

...

New files get their "normal" permission bits set to the source file's permissions masked with the receiving directory's default permissions (either the receiving process's umask, or the permissions specified via the destination directory's default ACL), and their special permission bits disabled except in the case where a new directory inherits a setgid bit from its parent directory.

当此选项关闭时,权限设置如下:

...

新文件将它们的“正常”权限位设置为源文件的权限,并使用接收目录的默认权限(接收进程的 umask 或通过目标目录的默认 ACL 指定的权限)进行屏蔽,并且它们的特殊权限位被禁用,除非在新目录从其父目录继承 setgid 位的情况。

I suspect your destination system has a typical umask like 022 which is preventing the group write bit from being set by rsync. Unfortunately --chmoddoesn't mention how the umask does or does not apply.

我怀疑你的目标系统有一个典型的 umask,比如 022,它阻止了 rsync 设置组写入位。不幸的--chmod是没有提到 umask 如何或不适用。

回答by Romain

You have to use --chmodwith -poptions, like this:

您必须--chmod-p选项一起使用,如下所示:

$ rsync -avz --chmod=o-rwx -p tata/ tata2/

And here is a full test:

这是一个完整的测试:

Create some file in a folder

在文件夹中创建一些文件

$ mkdir tata
$ mkdir tata2
$ cd tata
$ touch tyoto
$ touch tiuti

The default perms are: u=rw, g=r, o=r

默认权限是: u=rw, g=r, o=r

$ ls -l 
total 0
-rw-r--r-- 1 romain users 0 fév 16 11:48 tiuti
-rw-r--r-- 1 romain users 0 fév 16 11:48 tyoto

Try an rsync without params

尝试不带参数的 rsync

$ cd ..
$ rsync -avz tata/ tata2/

The destination perms are the same than the source files

目标权限与源文件相同

$ ls -l tata2
total 0
-rw-r--r-- 1 romain users 0 fév 16 11:48 tiuti
-rw-r--r-- 1 romain users 0 fév 16 11:48 tyoto

Specify the rsync options --chmod=o-rwx -p

指定 rsync 选项 --chmod=o-rwx -p

$ rsync -avz --chmod=o-rwx -p tata/ tata2/
$ ls -l tata2
total 0
-rw-r----- 1 romain users 0 fév 16 11:48 tiuti
-rw-r----- 1 romain users 0 fév 16 11:48 tyoto

And now your perms are ok.

现在你的烫发好了。