Include Exclude .. a canonical way

Matt McCutchen hashproduct at verizon.net
Fri Feb 24 02:55:01 GMT 2006


On Wed, 2006-02-22 at 11:24 -0800, Wayne Davison wrote:
>     rsync -avO --prune-empty-dirs --include=bookmarks.xml 
> 	      --filter='-! */' ~/.kde* some:dest/

I just discovered a way to transfer certain files and folders a few
levels below a generic exclude rule without having to include everything
on the way; in hindsight it seems so obvious that I'm really surprised
no one has discovered it yet.  End your exclude rules in * instead of
**, use --relative, and just list all the things you want included!  The
source arguments "sneak under" the generic exclude rule.  Example:
	rsync --exclude=/.kde* --relative ~/./ \
            ~/./.kde3.5/share/apps/konqueror/bookmarks.xml dest/

If you need to transfer a file or folder that matches a generic exclude
rule instead of merely being under a generic exclude rule, you need a
single higher-priority include rule specific to that file or folder,
just as you would if you didn't list the file or folder as a source
path.  If you just generate a source argument and a single high-priority
specific include rule for each thing you want to transfer, rsync will do
what you expect.

I've tried this approach with rsync-acl 2.6.7pre2 and it seems to work.
Note the ./ that marks the start of --relative path information; this
syntax was introduced in 2.6.7.  This approach improves upon the use of
--prune-empty-dirs in that the latter might omit empty directories that
you actually want; it also handles 99% of the cases that the "traverse"
sender filters I proposed would handle.
-- 
Matt McCutchen
hashproduct at verizon.net
http://hashproduct.metaesthetics.net/



More information about the rsync mailing list