How to exclude directories from source with --relative

Wayne Davison wayned at samba.org
Fri May 30 18:14:22 GMT 2008


On Tue, May 27, 2008 at 10:43:00AM -0700, Stuart Anderson wrote:
> Nuts. I was afraid that was going to be the answer. Unfortunately,
> it violates the very helpful advise given above, i.e., run with "-v"
> and add exclude rules for files you don't want to transfer based
> on the output seen.

That rule is not violated (the matching is correct), it is just that you
can't try to exclude something in the middle of a relative path that
you've specified.

You can work around the issue by moving higher in the directory
structure and using includes/excludes.  For example, instead of:

rsync -avR --exclude a/ /tmp/source/./[a-z]/* /tmp/destination                                                       

You'd change the copy to be:

rsync -av --exclude-from=file /tmp/source/ /tmp/destination/

and have an exclude file:

# First, we don't want that "a" dir (anchor it with a leading slash).
- /a/
# Next, this is our matching rule from the path above.
+ /[a-z]/
# Then, exclude everything else _in_this_dir_ (note leading slash).
- /*
# Finally, I added this rule to emulate the '*' above for a shell
# that omits dot files from its globbing.
- /*/.*

If you have any questions (such as how to adapt your real copy command),
let us know.

..wayne..


More information about the rsync mailing list