Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an 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 it's interrupted while doing this.

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.

Cheers.

share|improve this question
    
similar to stackoverflow.com/questions/7380234/… though I think Kyle may be right - sometimes it seems rsync waits for all files to complete, but sometimes it does delete the files before completion. Still a bit confused though. –  Chris2048 Apr 28 '12 at 11:32

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
    
As per my answer below I tried it with a couple of files, and files were only deleted if the complete operation was successful. That makes me think that the "transfer OK" signal you found is only permeated when the complete operation is successful. –  Daniel Andersson Mar 28 '12 at 15:56
    
If you try it with more than a few files, you'll see source files disappearing before the whole transfer is done. –  Kyle Jones Mar 28 '12 at 15:57
    
it looks like that when specifying directories and the recursive option, files in a are not deleted immediately –  Andre Holzner Nov 21 at 9:30

I tried it (and you could easily do it too, to be sure). They are removed after all files are transferred successfully. If the transfer is interrupted or another error occurs, the source files are not removed, even if some of them transferred OK.

EDIT: as per Kyle Jones's answer, the case might be different when many files are involved.

share|improve this answer

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.