Sync both sides with deleting from one side and creating files on both sides

Wayne Davison wayned at samba.org
Thu Jan 27 08:44:48 GMT 2005


On Tue, Jan 25, 2005 at 06:14:35PM +0100, gentoo at boxhorn-edv.com wrote:
> But the Problem is, rsync deletes on step 1 as well all documents,
> which have been created on side B

Exactly, since it is duplicating side A.  To do what you want you'll
need to either (1) implement your own delete functionality, or (2) add
an exclude for every new file on side B.  An example of "1" would be to
keep a list of the files that were last transferred from A to B (you can
glean this from the output of rsync), notice when a file goes missing,
and use ssh and a list of files to instruct xargs to remove the vanished
files (and, of course, leave off --delete from the rsync command).
Something like this might work (untested):

  rsync -avv somedir host:dest/ | tee xfer-output
  grep '^somedir/' xfer-output | sed 's/ is uptodate$//' | sort >file-list.new
  diff file-list.old file-list.new | sed -n 's/^< //p' | ssh host xargs rm -rf
  mv file-list.new file-list.old

Of course, you'd do well to add some error-checking to that for safety
(e.g. abort if the rsync command didn't finish successfully).

..wayne..


More information about the rsync mailing list