我正在尝试通过设置所有者和组rsync
,但似乎没有用。
这是命令:
sudo rsync -rlptDvz --owner=cmsseren --group=cmsseren /home/serena/public_html/ -e ssh root@ip:/home/cmsseren/public_html2/
文件可以正确同步,但似乎不会更改所有者和组。
我正在尝试通过设置所有者和组rsync
,但似乎没有用。
这是命令:
sudo rsync -rlptDvz --owner=cmsseren --group=cmsseren /home/serena/public_html/ -e ssh root@ip:/home/cmsseren/public_html2/
文件可以正确同步,但似乎不会更改所有者和组。
Answers:
听起来好像工作正常。使用--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...
ssh root@ip 'chown -R cmsseren:cmsseren /home/serena/public_html2/*'
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.
另外,-o
和-g
选项也是必需的。排除它们将无法更新其各自的属性,但不会产生任何错误。
rsync -og --chown=cmsseren:cmsseren [src] [dest]
这是在间接提到的手册页,其中指出,--chown
选项“是使用实现的--usermap
和--groupmap
内部”,和:
对于
--usermap
选项有什么影响时,-o
(--owner
)选项必须使用(或暗示),并且接收机将需要运行一个超级用户(也见--fake-super
选项)。对于
--groupmap
选项有任何效果,-g
(--groups
)选项必须被使用(或暗示),并且接收器将需要具有的权限来设置该组。
另一个解决方案可能是使用更改建立rsync
连接的远程用户--rsync-path
。我在这里发布了完整的解释: