uid/gid 不同时 rsync 如何保留所有权?
How does rsync preserve ownership when uid/gid differs?
部署新服务器并使用 rsync
迁移 /home
的全部内容后,我注意到组和用户所有权实际上得到了保留,尽管两者之间的 ID 不同服务器。
具体来说,我 运行 的命令是:
rsync -avz oldserver:/home/ /home
虽然我在新服务器上重新创建了所有相同的用户和组,但其中大多数的 ID 与旧服务器不同,但不知何故这个命令神奇地保持了正确的所有权(基于名称)并分配了新的 gid和 uid 在适用的情况下。我可以用 ls -n /home
.
来验证这一点
这怎么可能? rsync 是否进行某种名称查找?
是的,默认情况下 rsync 按名称匹配所有者和组。 --numeric-ids
.
的文档中有详细信息
--numeric-ids
With this option rsync will transfer numeric group and user IDs rather than using user and group names and mapping them at both ends.
By default rsync will use the username and groupname to determine what ownership to give files. The special uid 0 and the special group 0 are never mapped via user/group names even if the --numeric-ids
option is not specified.
If a user or group has no name on the source system or it has no match on the destination system, then the numeric ID from the source system is used instead.
部署新服务器并使用 rsync
迁移 /home
的全部内容后,我注意到组和用户所有权实际上得到了保留,尽管两者之间的 ID 不同服务器。
具体来说,我 运行 的命令是:
rsync -avz oldserver:/home/ /home
虽然我在新服务器上重新创建了所有相同的用户和组,但其中大多数的 ID 与旧服务器不同,但不知何故这个命令神奇地保持了正确的所有权(基于名称)并分配了新的 gid和 uid 在适用的情况下。我可以用 ls -n /home
.
这怎么可能? rsync 是否进行某种名称查找?
是的,默认情况下 rsync 按名称匹配所有者和组。 --numeric-ids
.
--numeric-ids
With this option rsync will transfer numeric group and user IDs rather than using user and group names and mapping them at both ends.
By default rsync will use the username and groupname to determine what ownership to give files. The special uid 0 and the special group 0 are never mapped via user/group names even if the
--numeric-ids
option is not specified.If a user or group has no name on the source system or it has no match on the destination system, then the numeric ID from the source system is used instead.