ユーザーが見つからない場合にrsyncを文句を言う方法

ユーザーが見つからない場合にrsyncを文句を言う方法

古いサーバーから新しいサーバーにファイルを移動しています。実際にこれを行うと(単純なテストではない)、新しいサーバーにすべての「ユーザー」ユーザー(システムではないユーザー、つまり> = 1000)を作成します。私の唯一の関心事は、これらのユーザーの1人(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を使用してファイルがコピーされないようにするにはどうすればよいですか?

ベストアンサー1

コマンド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

おすすめ記事