Rsync – Does –remove-source-files Delete Source Files One by One or After Completion?

file-transferrsync

I have a rsync command in an application that copies the contents of a folder to another machine. I have the option --remove-source-files because I'm only interested in having the files on the destination machine after the rsync has finished.

However, I was wondering how rsync behaves if it crashes or is interrupted while transferring files?

Consider I have two files to sync, a and b. Will rsync copy a, then delete it from source, and start copying b, or will it wait for both a and b to be copied to the destination machine before deleting them both? I've seen you can configure this behavior when deleting extraneous files with some flags, but found none about the removing of source files.

Best Answer

Checking the rsync code reveals that source files are removed as they are sent, although it may not happen immediately. rsync multiplexes its operations, so the message that a file was successfully received (and can therefore be deleted) might be buffered behind other data.

Related Question