LoginSignup
4
0

More than 3 years have passed since last update.

rsyncのオプション

Posted at

rsyncコマンドを使ったファイル転送スクリプトを作った時のメモ

文法

いくつかパターンがありますが、基本的にはコピー元(SRC)とコピー先(DEST)を指定すればファイルを転送してくれます。リモートホストに送ったり、リモートホストから取得することも可能です。

rsync [OPTION]... SRC [SRC]... DEST
rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
rsync [OPTION]... [USER@]HOST::SRC [DEST]

オプション

いくつか使ったものだけピックアップ。

オプション 意味 原文
-r 再帰的に転送 recurse into directories
-n 実際には転送せず情報だけ出力 show what would have been transferred
-c 最終更新日とファイルサイズではなく、checksumを見て更新する skip based on checksum, not mod-time & size
-b バックアップを作成 make backups (see --suffix & --backup-dir)
--backup-dir バックアップ先を指定 make backups into hierarchy based in DIR
-v 出力内容を増やす increase verbosity

補足

--backup-dir

下記のような説明があります。

In combination with the --backup option, this tells rsync to store all backups in the specified directory on the receiving side.

つまり、-bと組み合わせて使うと特定のディレクトリにコピーが可能です。bオプションが付いてないと何も起きません。

--backup-dirを付けた時のバックアップ先は保存先のディレクトリを基準とした相対パスか、絶対パスの2種類が指定できます。

-c(--checksum)

更新時間とファイルサイズではなく、checksumを用いて差分判定を行います。

 Without this option, rsync uses a "quick check" that (by default) checks if each file’s size and time of last modification match between the sender and receiver.

と書いてあることから、処理コストは高くなるようです。

また、checksumはrsyncのプロトコルバージョンによって判定に用いるアルゴリズムが変わるようです。気にすることはないと思いますが。

MD5かMD4によりハッシュ化された値を用いて比較されるため、ファイルの内容によって差分があるかを判定することができます。

For protocol 30 and beyond (first supported in 3.0.0), the checksum used is MD5.  For older protocols, the checksum used is MD4.

-n

これをつけるとドライランになります。
実際にファイル転送を行わずに対象ファイルなどの情報を出力できます。
デプロイスクリプトで使う時は確認に使えるので便利です。

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