我需要创建一个部署脚本来组合以下目录结构:
├── 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
一种方法是:
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/