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?

2 Answers 2


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.


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...

  • 1
    Careful. This may fail quite badly in the presence of filenames containing spaces. Oct 22, 2022 at 11:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .