linux – 在rsync中,如何排除与模式匹配的所有目录?
发布时间:2020-12-13 17:05:09 所属栏目:Linux 来源:网络整理
导读:在rsync中,我试图排除与模式匹配的子目录.但是,我无法让它发挥作用.我已经按照此处和Google上的几个示例进行了操作.但是,我没有得到正确的结果.这是我命令的选项: -avh --exclude 'branch*' --stats --delete --link-dest=$LNK 我的源目录结构是 /root /bra
在rsync中,我试图排除与模式匹配的子目录.但是,我无法让它发挥作用.我已经按照此处和Google上的几个示例进行了操作.但是,我没有得到正确的结果.这是我命令的选项:
-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* 感谢您的帮助/建议. 编辑 – 解决“可能的重复”标志 This question涉及已知的目录列表.我需要排除任何遵循模式的目录,即使这些目录尚不存在.也就是说,从我的例子中,可以添加名为/ branch *的其他目录.我需要使我的脚本面向未来,并且在添加与模式匹配的目录时避免编辑脚本,因为这些目录可能是临时的. 解决方法
您排除规则是正确的.但是,如果没有额外的参数–delete-excluded,rsync将不会删除目标上的排除文件:
例: # 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |