rsync - 如何在有多个来源时排除文件夹?

rsync - How to exclude a folder when there are multiple sources?

我正在尝试使用 --exclude 选项使用 rsync 备份多个目录。

我知道 --exclude 路径需要相对于源路径,但是当有多个源时会发生什么?

假设我想备份 /home/user/source_a/home/user/source_b,但想排除 /home/user/source_a/something

当我写--exclude=/something时,/home/user/source_a/something/home/user/source_b/something都会被排除(如果有/home/user/source_b/something)吗?

我显然误解了你的问题 - 所以我的第一个版本的回答是期望你想要排除 both 来源中的 'something' 目录。在这种情况下,需要在源代码中添加尾部斜杠。

要排除 only /home/user/source_a/something(not /home/user/source_b/something),您必须更上一层楼,以便 rsync 知道不同的来源。那么您的 rsync 命令将如下所示:

rsync -a --exclude=/source_a/something /home/user/source_a /home/user/source_b /target

只需删除源中的尾部斜杠,source_a 和 source_b 目录本身也将被传输。因此,现在可以从特定源中排除路径。