rsync
リモート環境とファイルやディレクトリを「同期(sync)する」コマンド。ローカル環境のみでも使用できる。
dry-run(お試し実行) したい -n
コマンドが意図した通りに動作するのかを事前確認する。
(-v は詳細出力用オプション)
$ rsync -nv test.txt test2.txt
test.txt
sent 50 bytes received 19 bytes 138.00 bytes/sec
total size is 19 speedup is 0.28 (DRY RUN)
帯域制限をしたい --bwlimit
サイズの大きなファイルを同期する時に負荷がかからないようにするため。
この場合、1024 kb/sec
$ rsync --bwlimit=1024 -v test.txt test2.txt
test.txt
sent 105 bytes received 35 bytes 280.00 bytes/sec
total size is 19 speedup is 0.14
ディレクトリごと同期したい -a
-a には色々な意味が含まれている。
$ rsync -av test1 test2
sending incremental file list
test1/
test1/a.txt
sent 128 bytes received 39 bytes 334.00 bytes/sec
total size is 0 speedup is 0.00
差分ファイルだけを同期したい -u
a.txt は同期対象になっていないことが分かる。
$ touch test1/b.txt
$ rsync -uv test1 test2
sending incremental file list
test1/
test1/b.txt
sent 153 bytes received 39 bytes 384.00 bytes/sec
total size is 0 speedup is 0.00
同期元で削除したファイルは、同期先でも削除したい --delete
a.txt が削除されていることが分かる。
$ rm test1/a.txt
$ rsync -av --delete test1 test2
sending incremental file list
deleting test1/a.txt
test1/
sent 89 bytes received 31 bytes 240.00 bytes/sec
total size is 0 speedup is 0.00