Filter file: selected directories only

Matt McCutchen matt at mattmccutchen.net
Sun Oct 4 00:00:55 MDT 2009


On Sun, 2009-10-04 at 00:29 +0400, rsync at xbit.ru wrote:
> I'm trying to create a filter file for rsync what saying which dirs to
> copy. For example  i need only /lib and /var/lib dirs from remote server.
> I say:
>  rsync -f ". /tmp/rsync_dirs"  --dry-run --verbose "remote:/"
> "/local_dir/".
> 
> File /tmp/rsync_dirs looks like:
> + /lib/
> + /var/
> -! /var/lib/*
> - /*
> 
> This doesnt work: it copies all /var/ dir except contents of /var/lib/.
> What's wrong?

Your third rule excludes all files that don't match "/var/lib/*",
and /var/lib is such a file since it has no third path component to
match the "*".  Hence the behavior you're seeing.

Instead, try this approach of including the /var/lib dir and then
excluding everything else at the /var/* level:

+ /lib/
+ /var/
- /*
+ /var/lib/
- /var/*

In practice, I have never found a legitimate use for "!" patterns and
believe they are a misfeature.  From the version-control history, it
appears that the only use Wayne had in mind for them was to replace the
traditional --include='*/' --exclude='*' (or --filter='S */'
--filter='H *') pattern, but I really don't see what was wrong with that
pattern, as it is consistent with the spirit of all other filter usage I
have seen.  Wayne, comments?

-- 
Matt



More information about the rsync mailing list