gpt4 book ai didi

rsync - 当 uid/gid 不同时,rsync 如何保留所有权?

转载 作者:行者123 更新时间:2023-12-04 02:57:51 25 4
gpt4 key购买 nike

部署新服务器并迁移 /home 的全部内容后使用 rsync我注意到实际上保留了组和用户所有权,尽管两个服务器之间的 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大概使用 getpwnam getgrnam 查找与用户名和组名关联的 uid 和 gid。

关于rsync - 当 uid/gid 不同时,rsync 如何保留所有权?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52067516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com