在一个rsync我试图排除与模式匹配的子目录。 但是,我无法让它工作。 我已经跟随在这里和谷歌上find的几个例子。 但是,我没有得到正确的结果。 这里是我的命令的选项:
-avh --exclude 'branch*' --stats --delete --link-dest=$LNK
我的源代码目录结构是
/root /branch1 /branch2 /branch3 /other /stillAnother /etc
这是备份脚本的一部分。 $ LNK是指向前一天的rsync目标的链接。
我不想要/ root / branch1,/ root / branch2,/ root / branch3。 或者他们的内容被同步。 但是,他们是。
这里是我已经尝试过的排除位:
--exclude=branch* --exclude='branch*' --exclude '/branch*' --exclude /branch*
感谢您的任何帮助/build议。
编辑 – 解决“可能重复”的标志
这个问题是关于一个已知的目录列表。 我需要排除模式后面的任何目录,即使这些目录还不存在。 即从我的例子,其他目录名为/branch*可能会被添加。 我需要使我的脚本具有前瞻性,并避免在添加与模式匹配的目录时编辑脚本,因为这些目录可能是临时的。
你排除规则是正确的。 但是,rsync不会删除目标上的排除文件,而无需额外的参数--delete-excluded :
--delete-excluded also delete excluded files from dest dirs
例:
# tree test test |-- 123 |-- branch1 |-- branch2 |-- branch3 `-- other # tree test2 test2 |-- 123 |-- branch1 |-- branch2 |-- branch3 `-- other # rsync -avh test/ test2 --delete --exclude='branch1' --delete-excluded sending incremental file list deleting branch1/ sent 140 bytes received 27 bytes 334.00 bytes/sec total size is 0 speedup is 0.00 # tree test2 test2 |-- 123 |-- branch2 |-- branch3 `-- other 3 directories, 1 file