如果找不到用户,如何使rsync抱怨

疯狂城堡

我正在将文件从旧服务器移到新服务器。到真正进行测试时(而不是仅仅进行测试),我将在新服务器上创建所有“用户”用户(非系统用户,即> = 1000)。我唯一的担心是我要移到主目录中的某个文件,这些文件将属于新服务器上不存在的这些用户之一(例如apache)。我在用着

rsync -az -e ssh src dest

以新服务器上的用户身份进行复制。它确实为现有用户保留用户(而不是ID)。但是,如果没有找到用户,它不会抱怨不存在的用户,而只是依靠数字id。该行为似乎与手册页中本段所述的相同:

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.  See also  the  comments  on  the
"use  chroot" setting in the rsyncd.conf manpage for information
on how the chroot setting affects rsync’s ability to look up the
names of the users and groups and what you can do about it.

尽管我还没有逐字阅读整个手册页,但是我所阅读的内容并没有为抱怨不存在的用户提供任何选择。确保新用户中存在目录(例如/ home)下的文件所有者/文件组的所有用户的最佳方法是什么。如果无法使用rsync进行操作,那么获取存在的所有用户/组的最佳方法是什么,因此我可以手动检查它们是否在新计算机上存在,或者在复制它们之前对其进行修复。

概括:

如何确保在运行rsync之后,没有使用数字ID而不是名称ID复制任何文件?

罗伊马

rsync命令没有直接处理此问题的机制,因此我将使用其他方法。我将扫描源文件系统树,收集那里存在的所有文件的用户名(和组):

# List of usernames owning files under 'src'
find src -printf "%u\n" | sort -u | tee /tmp/src.users

# List of group memberships for files under 'src'
find src -printf "%g\n" | sort -u | tee /tmp/src.groups

# Copy files to target system
scp -p /tmp/src.{users,groups} dest:/tmp/

然后,我将确保目标系统上存在所有可供使用的rsync用户。在目标系统上运行以下命令:

# List "missing" users
getent passwd | cut -d: -f1 | sort -u | comm -13 - /tmp/src.users

# List "missing" groups
getent group | cut -d: -f1 | sort -u | comm -13 - /tmp/src.groups

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事