SSH上的rsync仅保留www数据拥有的文件的所有权 [英] rsync over SSH preserve ownership only for www-data owned files

查看:219
本文介绍了SSH上的rsync仅保留www数据拥有的文件的所有权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用rsync将Web文件夹结构从本地服务器复制到远程服务器.两台服务器都是ubuntu linux.我使用以下命令,它运行良好:

I am using rsync to replicate a web folder structure from a local server to a remote server. Both servers are ubuntu linux. I use the following command, and it works well:

rsync -az /var/www/ user@10.1.1.1:/var/www/

本地系统和远程系统的用户名不同.根据我的阅读,可能无法保留所有文件和文件夹的所有者和组.可以,但是我只想为两个服务器上都存在的www-data用户保留所有者和组.

The usernames for the local system and the remote system are different. From what I have read it may not be possible to preserve all file and folder owners and groups. That is OK, but I would like to preserve owners and groups just for the www-data user, which does exist on both servers.

这可能吗?如果是这样,我将如何去做?

Is this possible? If so, how would I go about doing that?

**编辑**

这里提到了rsync能够保留远程文件同步上的所有权和组的信息: http://lists.samba.org/archive/rsync/2005-August/013203.html

There is some mention of rsync being able to preserve ownership and groups on remote file syncs here: http://lists.samba.org/archive/rsync/2005-August/013203.html

**编辑2 **

由于这里提供了许多有用的评论和答案,我最终获得了预期的效果.假设源计算机的IP为10.1.1.2,而目标计算机的IP为10.1.1.1.我可以在目标计算机上使用此行:

I ended up getting the desired affect thanks to many of the helpful comments and answers here. Assuming the IP of the source machine is 10.1.1.2 and the IP of the destination machine is 10.1.1.1. I can use this line from the destination machine:

sudo rsync -az user@10.1.1.2:/var/www/ /var/www/

这将保留具有通用用户名(如www-data)的文件的所有权和组.请注意,在没有sudo的情况下使用rsync不会保留这些权限.

This preserves the ownership and groups of the files that have a common user name, like www-data. Note that using rsync without sudo does not preserve these permissions.

推荐答案

您还可以使用--rsync-path选项在目标主机上sudo rsync:

You can also sudo the rsync on the target host by using the --rsync-path option:

# rsync -av --rsync-path="sudo rsync" /path/to/files user@targethost:/path

这使您可以在目标主机上通过user进行身份验证,但仍可以通过sudo获得特权写权限.您必须在目标主机上修改sudoers文件,以避免sudo要求输入密码. man sudoers或运行sudo visudo获取说明和示例.

This lets you authenticate as user on targethost, but still get privileged write permission through sudo. You'll have to modify your sudoers file on the target host to avoid sudo's request for your password. man sudoers or run sudo visudo for instructions and samples.

您提到您想保留www-data拥有的文件的所有权,而不是其他文件的所有权.如果确实如此,那么除非您实施chown或第二次运行rsync来更新权限,否则您可能不走运.无法告诉rsync仅保留一个用户的所有权.

You mention that you'd like to retain the ownership of files owned by www-data, but not other files. If this is really true, then you may be out of luck unless you implement chown or a second run of rsync to update permissions. There is no way to tell rsync to preserve ownership for just one user.

也就是说,您应该阅读有关rsync的--files-from选项的信息.

That said, you should read about rsync's --files-from option.

rsync -av /path/to/files user@targethost:/path
find /path/to/files -user www-data -print | \
  rsync -av --files-from=- --rsync-path="sudo rsync" /path/to/files user@targethost:/path

我还没有测试过,所以我不确定到底如何将管道查找的输出输出到--files-from=-中.毫无疑问,您需要进行实验.

I haven't tested this, so I'm not sure exactly how piping find's output into --files-from=- will work. You'll undoubtedly need to experiment.

这篇关于SSH上的rsync仅保留www数据拥有的文件的所有权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆