exclude an excluded file from being deleted by --delete-excluded

Wayne Davison wayned at samba.org
Thu Feb 9 09:46:34 GMT 2006


On Thu, Feb 09, 2006 at 05:35:11PM +1100, Craig Hammond wrote:
> I have a particular directory in my exclude list, but I want it
> excluded from --delete-excluded.

Sure, that's easy enough using filter rules.  Just add a protect filter
rule to what you have now and rsync will protect any matching files from
deletion:

    -f "protect /db/dir/"

If you aren't familiar with filter rules, you can think of a normal
exclude as having two filter effects:  it hides files on the sending
side, and it protects files from deletion on the receiving side.  Using
the --delete-excluded option turns off the protect feature of normal
excludes, but it has no effect on other filter rules, such as an
explicit protect.

While you're at it, I'd recommend switching your excludes over to hide
rules, which allows you to put all your rules into a single file and to
get rid of the --delete-excluded option.  For example, imagine these
lines in a file:

H /unneeded/dir/
H *.trash
P /db/dir/
- /hide/and/protect/

The "H" is the short way to specify "hide", "P" is short for "protect",
and "-" (short for "exclude") does both.  If you need to specify the
opposite of a hide, see the "show" (S) filter rule.

You then use a --filter (-f) option to read the above file instead of
using --exclude-from:

    rsync -av -f ". /some/filter-file" --del src/ dest/

The "." is the merge rule that reads in the contents of the specified
file (yes, you can merge a filter file from inside another filter file).

..wayne..


More information about the rsync mailing list