rsyncglobrdiff-backup

How to exclude wildcard directory but include wildcard files using rdiff-backup?


I am using rdiff-backup. Really awesome simple powerful backup tool. However I am fighting with wildcard glob patterns. I have this directory structure:

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

In each cache directory are original files and cache files. Original files are named simply 1.jpg, 2.png, 3.gif, and so on. Cache files have some string attached to the original filename.

So I want to backup all the /data/*/cache directories, but to include only original files, not the cache files.

I am using this command:
rdiff-backup --exclude **/cache --include **/cache/+([0-9]).+([a-z]) /data /backup

But rdiff-backup returns this and I am lost:

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.

Solution

  • From 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.
    

    So, in your case, it is complaining about the final --include because if a file gets there (i.e. it isn't matched by the previous --exclude) it will be included whether or not it matches the --include. That's what the error message was trying to say.

    As for how to accomplish your goal...

    Assuming you do want to exclude only paths of the form: /data/*/cache/[0-9]*.[a-z][a-z][a-z]?* just specify that:

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

    This should work (I haven't tested it).