rsyncを使用したディレクトリのマージ(結合)

rsyncを使用したディレクトリのマージ(結合)

次のディレクトリ構造を結合する展開スクリプトを生成する必要があります。

├── LIB_COMMON
│   ├── file1.php 
│   ├── file2.php
│   ├── file3.php
│   └── file4.php
├── LIB_CZ
│   ├── file2.php
│   ├── file3.php
│   ├── file5.php
│   └── file6.php

...結果は次のようになります。

├── LIB_RESULT
│   ├── file1.php ...with content from LIB_COMMON
│   ├── file2.php ...from LIB_CZ
│   ├── file3.php ...from LIB_CZ
│   ├── file4.php ...from LIB_COMMON
│   ├── file5.php ...from LIB_CZ
│   └── file6.php ...from LIB_CZ

1つの方法は次のとおりです。

rsync LIB_COMMON/ LIB_RESULT/ --delete-after
rsync LIB_CZ/ LIB_RESULT/

...しかし、常に多くのファイルを転送します。

他の方法は次のとおりです。

cp LIB_COMMON/ TMP/ 
cp LIB_CZ/ TMP/
rsync TMP/ LIB_RESULT/ --delete-after

それでは、これを達成するためのエレガントな方法を知っている人はいますか?

答え1

rsync -avz LIB_COMMON/ LIB_CZ/ LIB_RESULT/ --delete-after

lib_common/これにより、&の内容がフォルダlib_cz/に同期されます。lib_result/

答え2

別の順序で私のために働く

~/test$ ll a/
-rw-r--r-- 1 jakub jakub   18 Jun  8 10:19 file1
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file2
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file3

~/test$ ll b/
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file2
-rw-r--r-- 1 jakub jakub   13 Jun  8 10:19 file3
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file4

~/test$ ll c/
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:22 file5

~/test$ rsync -avz b/ a/ c/ --delete-after
building file list ... done
./
file1
file2
file3
file4
deleting file5

sent 345 bytes  received 94 bytes  878.00 bytes/sec
total size is 31  speedup is 0.07

~/test$ ll c/
-rw-r--r-- 1 jakub jakub   18 Jun  8 10:19 file1
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file2
-rw-r--r-- 1 jakub jakub   13 Jun  8 10:19 file3
-rw-r--r-- 1 jakub jakub    0 Jun  8 10:18 file4

答え3

他の質問に対する有用な答え:https://stackoverflow.com/a/22558474/652971

私はこれをします:

rsync $(
 find ./one/ -type f $(printf "! -name %s " `ls ./two/`)
 find ./two/ -type f 
) user@remote:/path/

関連情報