rsync 忽略 --chown/--usermap

rsync 忽略 --chown/--usermap

我正在使用模块运行 ansible synchronize,模块下面运行 rsync。我的问题与 ansible 无关,因为我从调试输出中获取了 rsync 命令并手动运行它 - 仍然是同样的问题。

我运行的命令是:

/usr/bin/rsync --delay-updates -F --rsync-path="sudo rsync" --compress --delete-after --archive "/local/path" "[email protected]:/remote/path" --chown=myuser:myuser

无论我尝试什么 - 我最终都会得到属于的目录root:root

因此,我现在可以成功以 root 身份运行 rsync,因此它应该具有所有必要的权限。我还尝试过--usermap=*:myuser --groupmap=*:myuser- 什么都没有。

我补充说--chmod=750-未被应用。

在调试输出(-vvvv)中,我可以再次看到我的参数,但仅此而已。

没有警告,没有错误,但后来也没有提及任何包含“用户”,“组”,“chown”等的内容...... rsync 在 Debian 8 上是 3.1.1。

任何帮助,将不胜感激...

答案1

系统chown调用(以及扩展的chownrsync --chown命令)只能由 来使用root。您正在以用户身份连接到远程系统ansible,因此远程系统不允许该操作。该rsync命令识别出它不是以root远程系统的身份运行的,因此它会默默忽略该--chown选项和其他类似选项(例如--mapuser)。

rsync 手册关于此行为并没有明确说明,但如果您--super同时指定了该选项,则会导致rsync远程系统假定它正在以 身份运行root,即使它不是。这将允许它尝试chown操作,并在失败时产生错误。

编辑:

如果你确实设法rsync在远程系统上执行root(例如,使用--rsync-path="sudo rsync"),你仍然需要添加几个选项才能--chown使用。手册指出:

--chown=USER:GROUP
    This option forces all files to be owned by USER with group GROUP.
    This is a simpler interface than using --usermap and --groupmap
    directly, but it is implemented using those options internally, so
    you cannot mix them.

以下是手册中关于--usermap和 的说明--groupmap

--usermap=STRING, --groupmap=STRING
    ...
    For the --usermap option to have any effect, the -o (--owner)
    option must be used (or implied), and the receiver will need to
    be running as a super-user (see also the --fake-super option).
    For the --groupmap option to have any effect, the -g (--groups)
    option must be used (or implied), and the receiver will need to
    have permissions to set that group. 

除了使用--rsync-path在 下运行它之外,还sudo可以尝试添加-o和选项。-g

答案2

sudo不是罪魁祸首...部分是我的错,也许这也是一个与预期不同的错误/功能。

我的 ansible 任务将源文件夹名称添加到目标路径,从而创建该路径,然后在该文件夹内创建源文件夹,从而有效地将文件夹结构加倍/destination/path/source/source/...

--chmod正在应用于第二个source文件夹,但不应用于作为目标结构的一部分创建的文件夹。因此,顶部source属于根,但第二个source属于它应该属于的用户。

修复了我的 ansible 任务以使用正确的路径,因此也解决了这个问题。

我想知道是否还应该期望rsync它创建的chown/chmod文件夹作为目标路径的一部分?

相关内容