R.A. Epigonos et al.

[rsync] ディレクトリのマージ

ディレクトリをマージしたい。その際に変更のあったファイルは元ディレクトリに残しておきたい。

bディレクトリとaディレクトリが以下のような構造とする。ただし、a/hoge/fuga/00.txtとb/hoge/fuga/00.txtは別物。

$ mkdir -p a/00/01 b/00/01 b/01 && touch a/00.txt a/00/01/02.txt b/00.txt b/00/01/02.txt b/01/00.txt b/01/01.txt && echo "hoge" > b/00/01/02.txt
$ find | sort
.
./a
./a/00
./a/00.txt
./a/00/01
./a/00/01/02.txt
./b
./b/00
./b/00.txt
./b/00/01
./b/00/01/02.txt
./b/01
./b/01/00.txt
./b/01/01.txt

a,bディレクトリをマージ。別物はaディレクトリからcディレクトリに移動。同じファイル、パスの異なるファイルはaディレクトリに移動。

$ rsync -av --checksum --remove-source-files --backup --backup-dir=`pwd`/c ./b/ ./a &&  find b -type d -empty -delete
sending incremental file list
00/01/02.txt
01/
01/00.txt
01/01.txt

sent 332 bytes  received 75 bytes  814.00 bytes/sec
total size is 5  speedup is 0.01
$ find | sort
.
./a
./a/00
./a/00.txt
./a/00/01
./a/00/01/02.txt
./a/01
./a/01/00.txt
./a/01/01.txt
./c
./c/00
./c/00/01
./c/00/01/02.txt

別物ファイルは元ディレクトリに残しておきたいけど、うまい方法が見つからない。

$ rsync  -n -avv --checksum --remove-source-files --ignore-existing a/ b

ソーシャルブックマーク

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

ChangeLog

  1. Posted: 2010-08-19T17:08:23+09:00
  2. Modified: 2010-08-19T17:08:23+09:00
  3. Generated: 2023-08-27T23:09:11+09:00