0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rsync 逆引きメモ

Posted at

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?