Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We use rsync to copy filesystem contents from one machine to another as a backup. We first run MACHINE-X->MACHINE-Y rsync for a straight backup with the --delete and --delete-excluded switches We also run an internal Rsync between the MACHINE-Y destination, and another folder on MACHINE-Y with either of the delete flags. This maintains a non-destructive copy in the event someone inadvertently deletes a file on MACHINE-X. However, it also has the overhead of being a complete copy of what has already been synchronized.

Ideally I want to be able to run the non-destructive rsync in such a way that the destination ONLY receives the deleted files and so avoids unnecessary duplication . Is there any way to do this?

share|improve this question
add comment

2 Answers

You could use -i --dry-run to get the list of changes between your two folders and then only keep the files that have been deleted.

However, most people do backups with rsync by first doing rsync and then cp -al of the backed up data (e.g. current) into a different directory (e.g. archive). The -l argument tells cp to not copy the data but to just create a hardlink. That way, you have the same data available under current and archive, but every file occupies the disk space only once (e.g. without the overhead you are experiencing now).

Later, as soon as you again rsync your server to current, rsync will update the all the files that have changed and delete the files that have been deleted. The files in archive, however, will not be touched.

Of course, you can create as many archive folders as you want. Also note that rsync offers the --link-dest option, which can automatically create the archive folder during the rsync run, without having to run cp -al. See the man page for more information.

share|improve this answer
add comment

You can do this simpler:

find dir1 | ssh host2 " \
  cat > tmpfile1 ; \
  find dir2 > tmpfile2 ; \
  join -a1 tmpfile1 tmpfile2 | \
  xargs rm -rf ; \
  rm tmpfile1 tmpfile2"

At least this is plain shell without rsync...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.