2014-10-10 61 views
1

我正在使用rdiff-backup。真的很棒的简单强大的备份工具。不过,我正在与通配符模式作斗争。我有这个目录结构:如何使用rdiff-backup排除通配符目录但包含通配符文件?

/data/aaa/cache 
/data/bbb/cache 
/data/ccc/cache 
etc.... 

在每个缓存目录中都有原始文件和缓存文件。原始文件简单地命名为1.jpg,2.png,3.gif等等。缓存文件具有附加到原始文件名的一些字符串。

所以我想备份所有/ data/*/cache目录,但只包含原始文件,而不包含缓存文件。

我使用这个命令:
rdiff-backup --exclude **/cache --include **/cache/+([0-9]).+([a-z]) /data /backup

但rdiff进行备份的回报这一点,我很失落:

Found interrupted initial backup. Removing... 
Fatal Error: Last selection expression: 
    Command-line include glob: **/cache/+([0-9]).+([a-z]) 
only specifies that files be included. Because the default is to 
include all files, the expression is redundant. Exiting because this 
probably isn't what you meant. 
+0

是否要排除不在缓存目录下的任何*其他文件或目录? – 2014-10-15 19:40:54

回答

1

http://rdiff-backup.nongnu.org/rdiff-backup.1.html

A given file is excluded by the file selection system exactly 
    when the first matching file selection condition 
    specifies that the file be excluded; otherwise the file is included. 

...

For instance, 

      rdiff-backup --include /usr --exclude /usr /usr /backup 

    is exactly the same as 

      rdiff-backup /usr /backup 

    because the include and exclude directives match exactly the same 
    files, and the --include comes first, giving it precedence. 

因此,就你而言,它抱怨最后的--include,因为如果一个文件到达那里(即它与以前的--exclude不匹配)将包括它是否与--include匹配。这就是错误信息试图说的。

至于如何实现自己的目标......

假设你想排除形式的路径:/data/*/cache/[0-9]*.[a-z][a-z][a-z]?*只是规定:

rdiff-backup --exclude '/data/*/cache/[0-9]*.[a-z][a-z][a-z]?*' --exclude '*' /data /backup 

这应该工作(我的天堂没有测试过)。

+0

感谢您的努力,但是我无法使用您的解决方案,因为我的场景有点复杂。为了这个问题,我简化了它。在我的真实例子中,我备份了更多的目录,所以我不能使用'--exclude'*'',因为我通常需要将它们全部包含在内,而不是全部排除它们。希望,如果你可以修改你的答案。再次感谢 – Frodik 2014-10-18 19:29:50

+0

那么,你想排除哪些文件和目录?只是缓存文件? – 2014-10-21 18:52:20

+0

好吧,这里有一个可能的答案...希望你还在听。 – 2014-10-28 21:49:39

2

你可能想要做两个步骤:

  1. 创建要排除所有如文件的列表与发现。 -name“** /缓存”> excludes.lst
  2. 使用清单,--exclude-文件列表excludes.lst

这种方式可以避免与水珠选项战斗,你必须完全控制你的不包括