deleting remote dirs I no longer want to backup

Wayne Davison wayned at samba.org
Fri Jan 20 19:27:04 GMT 2006


On Fri, Jan 20, 2006 at 07:30:00PM +0100, Christophe LYON wrote:
> My original command was:
> rsync -aR --exclude=dirb --exclude-deleted dira dirb /tmp

I assumed the -R was unneeded because dira and dirb have no path
information.  If that info was elided, then things may become much more
complicated because you need to send the parent dir of the dir you want
to delete (since rsync only deletes in directories that it sends).

If all you want to do is to send all the */release-1.0 dirs (each one
level deep) while also having any already-copied dirs vanish when the
dir vanishes on the sender, you'd be better off using includes/excludes
from the top of the transfer:

rsync -a --include='/*/' --include='/*/release-1.0/' --exclude='/*/*' . /tmp

The bad thing about that is that it can create extra empty dirs in the
root of the transfer.  You'd need to do something like this to exclude
them:

for dir in `ls -1d */`; do
    if test ! -d $dir/release-1.0; then
	echo "- $dir"
    fi
done | rsync -a --exclude-from=- --include=[... as above ...]

There are also more complicated solutions that you can use that would
allow you to specify directories at any level, but you'd need to make a
script that would tell rsync to send the parent dir of the directory to
send, to include the directory to send, and to exclude everything else
in that dir (and put all the includes before all the excludes, just in
case multiple dirs are inside the same parent dir).

> I thought that mentioning dirb in the list of copied dirs would make
> the --exclude switch work (at least taken into account).

It is taken into account -- it excludes the dirb dir from even being put
into the file list, so rsync does nothing with it.  And since you didn't
transfer the parent dir of dirb, it also doesn't get deleted.  Using an
exclude of "dirb/**" doesn't match dirb itself, so combined with
--delete-excluded, that would delete the contents of the directory
without deleting the directory itself (as long as the directory still
exists on the sending side).

..wayne..


More information about the rsync mailing list