我正在尝试通过设置所有者和组rsync,但它似乎不起作用。
这是命令:
sudo rsync -rlptDvz --owner=cmsseren --group=cmsseren /home/serena/public_html/ -e ssh root@ip:/home/cmsseren/public_html2/
Run Code Online (Sandbox Code Playgroud)
文件同步正确,但似乎没有更改所有者和组。
小智 77
rsync 的3.1.0 版引入了Thomas 提到的--usermap和--groupmap,但也引入了便利选项--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.
If either the USER or GROUP is empty, no mapping for the omitted user/group will
occur. If GROUP is empty, the trailing colon may be omitted, but if USER is
empty, a leading colon must be supplied.
If you specify "--chown=foo:bar, this is exactly the same as specifying
"--usermap=*:foo --groupmap=*:bar", only easier.
Run Code Online (Sandbox Code Playgroud)
此外,-o和-g选项是必需的。排除它们将无法更新它们各自的属性,但不会产生错误。
rsync -og --chown=cmsseren:cmsseren [src] [dest]
Run Code Online (Sandbox Code Playgroud)
手册页中间接提到了这一点,其中指出该--chown选项“是使用--usermap和--groupmap内部实现的”,并且:
要使该
--usermap选项生效,必须使用(或隐含)-o(--owner) 选项,并且接收器需要以超级用户身份运行(另请参阅该--fake-super选项)。要使该
--groupmap选项产生任何效果,必须使用(或暗示)-g(--groups) 选项,并且接收者需要具有设置该组的权限。
小智 20
听起来它工作正常。使用--owner和--group以保存(未设置)所有者和组名......这意味着你不希望他们转移后更改。
如果不使用这些选项,用户和组将更改为接收端的调用用户。如果要指定其他用户,则需要向chown脚本添加命令。
-o, --owner
This option causes rsync to set the owner of the destination file to be
the same as the source file, but only if the receiving rsync is being run
as the super-user (see also the --super and --fake-super options). Without
this option, the owner of new and/or transferred files are set to the invoking
user on the receiving side...
-g, --group
This option causes rsync to set the group of the destination file to be the same as
the source file. If the receiving program is not running as the super-user (or if
--no-super was specified), only groups that the invoking user on the receiving side
is a member of will be preserved. Without this option, the group is set to the default
group of the invoking user on the receiving side...
Run Code Online (Sandbox Code Playgroud)
rsync 的最新版本(至少 3.1.1)允许您指定“远程所有权”:
--usermap=tom:www-data
Run Code Online (Sandbox Code Playgroud)
将 tom 所有权更改为 www-data(又名 PHP/Nginx)。如果您使用 Mac 作为客户端,请使用 brew 升级到最新版本。在您的服务器上,下载档案源,然后“制作”它!
| 归档时间: |
|
| 查看次数: |
91390 次 |
| 最近记录: |