【问题标题】:rsync - How to exclude a folder when there are multiple sources?rsync - 当有多个来源时如何排除文件夹?
【发布时间】:2019-07-10 12:45:44
【问题描述】:

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

我知道--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)?

【问题讨论】:

    标签: rsync


    【解决方案1】:

    我显然误解了您的问题 - 所以我的第一个答案版本是希望您希望排除 both 来源中的“某物”目录。在这种情况下,需要在源代码上加上斜线。

    要在您的评论中排除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 目录本身。因此,现在可以排除来自特定来源的路径。

    【讨论】:

    • 谢谢。那么,如果我只想--exclude/home/user/source_a/something(而不是/home/user/source_b/something ),我该怎么办?
    猜你喜欢
    • 2015-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-05
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多