R.A. Epigonos et al.

[rsync] 復数ディレクトリを統合する

複数のディレクトリ以下の要素を 1 つのディレクトリに移動したい。複数の移動元に同じファイル名のファイルが含まれている場合、単純な mv を使うと、同名のファイルを上書きしてしまう危険性がある。異なるファイル名のファイルに関しては 1 つのディレクトリにまとめて、同じファイル名のファイルは別に用意したディレクトリに移動したうえで、後から手作業で確認したいい。

テストディレクトリの作成。src0とsrc1の中身をdstに移動することを考える。ただし、src0とsrc1に含まれるファイルは独立に編集されるとする。このディレクトリを定期的にバックアップすることを考える。

$ mkdir src0
$ mkdir src1
$ touch src0/test0.txt
$ touch src0/test1.txt
$ touch src1/test0.txt
$ touch src1/test1.txt
$ echo hoge > src0/test0.txt
$ ls -R
.:
src0  src1

./src0:
test0.txt  test1.txt

./src1:
test0.txt  test1.txt

rsyncでsrc0、src1の順にバックアップを行うと、チェックサムで変化のあったと判断されたファイルは別ディレクトリに移動される。このとき、移動されるのはバックアップ先にあったファイル。この場合は、先にバックアップが行われた/path/to/src0/の中にあったファイルがバックアップディレクトリに移動される。

$ rsync -avv --checksum --backup --backup-dir=/path/to/dst_bkup/ /path/to/src0/ /path/to/dst
backup_dir is /path/to/dst_bkup/
sending incremental file list
created directory /path/to/dst
delta-transmission disabled for local transfer or --whole-file
./
test0.txt
test1.txt
total: matches=0  hash_hits=0  false_alarms=0 data=5

sent 194 bytes  received 53 bytes  494.00 bytes/sec
total size is 5  speedup is 0.02
$ rsync -avv --checksum --backup --backup-dir=/path/to/dst_bkup/ /path/to/src1/ /path/to/dst
backup_dir is /path/to/dst_bkup/
sending incremental file list
delta-transmission disabled for local transfer or --whole-file
./
test0.txt
test1.txt
backed up test0.txt to /path/to/dst_bkup/test0.txt
total: matches=0  hash_hits=0  false_alarms=0 data=0

sent 149 bytes  received 37 bytes  372.00 bytes/sec
total size is 0  speedup is 0.00

リファレンス

  1. rsync
  2. sync "--backup-dir" - Google 検索
  3. rsyncでバックアップする際の超絶便利オプション - edy::diary
  4. rsync "--checksum" - Google 検索

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2010-04-19T17:32:04+09:00
  2. Modified: 2010-04-19T17:32:04+09:00
  3. Generated: 2023-08-27T23:09:14+09:00