
ランダムファイルを生成するために、次のスクリプトを作成しました。
#!/bin/bash
for dir in `seq 1 10`
do
mkdir /root/mandar/RsyncSrc/$dir
cd /root/mandar/RsyncSrc/$dir
for file in `seq 11 20`
do
touch /root/mandar/RsyncSrc/$dir/$file
done
done
したがって、ディレクトリの内容は/root/mandar/RsyncSrc
次のようになります。
1 10 2 3 4 5 6 7 8 9 mkfiles.sh
ケース1(cp
コマンドを使用):
次のコマンドを実行してディレクトリ/root/mandar/RsyncSrc
と同期します。/root/mandar/RsyncDst
cp -R /root/mandar/RsyncSrc/* /root/mandar/RsyncDst/
ディレクトリの内容/root/mandar/RsyncDst
:
1 10 2 3 4 5 6 7 8 9 mkfiles.sh
rsync
dry-run
次に、次のように影響を受けるファイルのリストを取得するために実行します。
rsync -avzm --stats --safe-links --dry-run --ignore-existing --human-readable /root/mandar/RsyncSrc/* /root/mandar/RsyncDst/ > test.log
文書の内容test.log
:
building file list ... done
1/
10/
2/
3/
4/
5/
6/
7/
8/
9/
Number of files: 112
Number of files transferred: 0
Total file size: 234 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 926
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 963
Total bytes received: 42
sent 963 bytes received 42 bytes 2.01K bytes/sec
total size is 234 speedup is 0.23 (DRY RUN)
ケース2(rsync
コマンドを使用):
すべてを削除/root/mandar/RsyncDst
し、次のコマンドを実行してデータを同期しました。
rsync -avzm --stats --safe-links --ignore-existing --human-readable /root/mandar/RsyncSrc/* /root/mandar/RsyncDst/
次に、dry-run
次のように再実行します。
rsync -avzm --stats --safe-links --dry-run --ignore-existing --human-readable /root/mandar/RsyncSrc/* /root/mandar/RsyncDst/ > test.log
今回は内容はtest.log
こんな感じです。
building file list ... done
Number of files: 112
Number of files transferred: 0
Total file size: 234 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 926
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 933
Total bytes received: 12
sent 933 bytes received 12 bytes 1.89K bytes/sec
total size is 234 speedup is 0.25 (DRY RUN)
rsync
ケース2の場合、ログファイルにファイル/ディレクトリが表示されないのはなぜですか?- ログにファイルのリストを表示する必要がある場合
rsync
(ケース2)どうすればよいですか?
答え1
-a
これは、コピーを実行するときにこのオプションを使用し、rsync
-aオプションを使用しなかったためですcp
。これにより、コピーされたファイルのタイムスタンプはcp
保存されません。
PS rsync に追加-v
オプションを指定すると、追加出力が発生します。わずかに異なる出力を報告するrsyncバージョン3.1.0プロトコルバージョン31を使用していますが、結果はユーザーと同じです。初期コピーで-aオプションを使用すると、cp
rsyncはrsyncDstCpディレクトリとrsyncDstRsyncディレクトリに同じコンテンツを出力します。