宛先の所有者と権限による rsync は可能ですか?

宛先の所有者と権限による rsync は可能ですか?

ソース サーバーの所有者の 1 人は root です。

----/home/sub1/test1 
----/home/sub2/test1

ローカルマシンが宛先です。

----/home/sub1/test1 owner by user1
----/home/sub2/test1 owner by user2

ローカル所有者を変更せずに、ソース サーバーからローカル マシンに新しい更新ファイルを同期するにはどうすればよいですか?

編集

フォルダーが多数あり、ローカル マシンにも所有者が多数存在するため、1 つのコマンドですべてのソースを同期する必要があります。可能でしょうか?

ありがとう。

答え1

移転後に変更されることを望まないようですね。

以下のコマンドを試してください:

rsync -avr -o -g /source/directory user@:destinationHost/destination/directory

これらのオプションを使用しない場合、ユーザーとグループは受信側で呼び出したユーザーに変更されます。他のユーザーを指定する場合は、スクリプトに chown コマンドを追加する必要があります。

-o, --owner
    This option causes rsync to set the owner of the destination file to be 
    the same as  the source file, but only if the receiving rsync is being run 
    as the super-user (see also the --super and --fake-super options). Without 
    this option, the owner of new and/or transferred files are set to the invoking 
    user on the receiving side...

-g, --group
    This option causes rsync to set the group of the destination file to be the same as 
    the source file. If the receiving program is not running as the super-user (or if
    --no-super was specified), only groups that the invoking user on the receiving side
    is a member of will be preserved. Without this option, the group is set to the default
    group of the invoking user on the receiving side...

SEE MAN rsync

答え2

あなたにとって良い選択肢は、別の物理ファイルシステム転送であると仮定して、ソースから宛先にrsyncを実行することだと思います。

rsync -e 'ssh -p 22' -quaxz --bwlimit=1000 --del --no-W --delete-excluded --exclude-from=/excludedstufflist /sourcedir serverIP:/destinationdir

そして、新しいシステムの適切な場所にすべてがコピーされたら、ソースシステムからのデータにシステムが与えた新しいUIDを調べます。おそらく1001、1002などです。その場合は、

find /destinationdir -user 1001 -exec chown username '{}' \;
find /destinationdir -user 1002 -exec chown otherusername '{}' \;
etc.

はい、最後の作業を 100 回実行する必要がありますが、rsync 中に使用される UID シーケンスがわかっていれば、簡単にスクリプト化できます。私はこれを一度実行し、約 60 人のユーザーを 1 つのサーバーから別のサーバーに移行しましたが、かなりうまくいきました。グループ権限を置き換える必要もありましたが、同様の作業でした。

chown --from=oldguy newguy * -R
chown --from=:friends :family * -R

そういうものです。これを使っていただければ幸いです。

答え3

これを 1 つのコマンドで実行することはできません。ただし、100 人以上のユーザーがいる場合でも、タスクを自動化するのは非常に簡単なので、1 つのコマンドにこだわる理由がわかりません。

必要がある引くrsyncこのシナリオでは、宛先マシンからデータを転送します。理論的には、リバーストンネルを介してソース サーバーから転送を実行することも可能になりますsshが、これはかなり複雑になります。

for testdir in /home/sub*/test1
do
    owner=$(stat -c %u "$testdir")
    rsync -avP --chown "$u" sourceserver:"$testdir"/ "$testdir"/
done

フラグがない場合は、--chown次の 2 つの手順でこれをエミュレートできます。

for testdir in /home/sub*/test1
do
    owner=$(stat -c %u "$testdir")
    rsync -avP --no-owner sourceserver:"$testdir"/ "$testdir"/
    chown -R "$u" "$testdir"                   # If possible
    # find "$testdir" -exec chown "$u" {} +    # Otherwise
done

バリアントを使用する必要がありfind、 が をfind理解しない場合は、少し効率の悪いもの(バックラッシュ セミコロン)+に置き換えます。\;

関連情報