Exclude directory from --delete

Matt McCutchen matt at mattmccutchen.net
Sat Oct 3 20:21:44 MDT 2009

On Sat, 2009-10-03 at 15:47 -0700, J. Ellis wrote:
> I have the following 3 commands which are supposed to run every night
> to back up my web server:
> rsync -avve ssh --numeric-ids --delete --ignore-errors
> myuser at myisp.com:/usr/home/myuser /Volumes/Downloads
> rsync -avve ssh --copy-links --numeric-ids --delete --ignore-errors
> myuser at myisp.com:/usr/home/myuser/mail_boxes /Volumes/Downloads/myuser/mail_boxesBU
> rsync -avve ssh --copy-links --numeric-ids --delete --ignore-errors
> myuser at myisp.com:/usr/home/myuser/mail_boxes /Volumes/Downloads/myuser/mail_boxesBU
> The way this works is that there are two symlinks on the server to the
> mail_boxes and public_html directories. I didn’t want all the symlinks
> within those directories to be followed, so these I backup separately
> to mail_boxesBU and public_htmlBU respectively.

There happens to be a trick for "copying a few dirlinks" without copying
all of them: use --relative and specify an additional source argument
that goes through each symlink with a trailing slash.  E.g.:

rsync -avve ssh --numeric-ids --delete --ignore-errors -R \
	myuser at isp.com:/usr/home/./myuser \
	myuser at isp.com:/usr/home/./myuser/mail_boxes/ \
	myuser at isp.com:/usr/home/./myuser/public_html/ \

For more about this, see:


> Unfortunately, when the first command is run, both are deleted from
> the local volume, and then must be completely downloaded from scratch
> each night after the deletion, instead of simply being updated. This
> doesn’t always work for some reason, and the next morning one or both
> of the directories are just gone.
> Is there some way of excluding the mail_boxesBU and public_htmlBU
> directories from --delete?

If you want to keep your existing approach, yes, you can just use
--exclude='/myuser/mail_boxesBU' and --exclude='/myuser/public_htmlBU'.


More information about the rsync mailing list