Getting rsync to delete source files that already exist on destination

rsync

I have a cron job that uses rsync to periodically transfer all files that appear in a specific directory on server A to somewhere on server B. I use --partial and --append-verify as the files are large. I also use the remove-source-files option to deletes the files on server A when they are transferred. As per the man page, rsync only delete the source files after all file transfers have completed on a specific run.

This works fine most of the time, except if the transfer is interrupted partway through due to a network failure, after a few files have already been transferred. On the next run, the program sees some of the files already in the destination and correctly determines they don't need to be re-transferred. However, since they were not part of that transfer run, the files in the source server do not get deleted. Over time they build up.

Is there a way to tell rsync to delete the source files on the subsequent run, if they exist in the destination, or is this something I'll have to solve by writing my own scripts?

Best Answer

Honestly, its not really much of an answer, because it's kind of a hack way of getting the results you are requesting. So here goes:

If you trim out the --append-verify command and replace it with the --update command, leave all the other options and run the RSYNC without it.

This will delete all the source files while copying the files that have been modified.

Related Question