Rsync command does incremental copying or overwrites the file

rsync

rsync command is used to sync a folder data to another folder. I want to know if this command overwrites the entire file and sync or copies only the new file or changed file. Does it prompt if similar name file is found in destination folder??

Specifically, I'm using rsync -rvh /usr/local/aryan/ /usr/local/aryan and it overwrote all the files from local machine to the remote machine. I copied 10 files manually to remote location and then used above rsync command to sync 20 files including first 10 files as well. After rsync -rvh command, I could see all the files in the remote location had same time. It means all the files got overwritten.

Best Answer

rsync will generally create a new version of a file alongside the destination, and then switch it across to the destination name at the last moment, when it is complete. The new version can be created either using deltas, i.e. changes between the source and destination, or as a full copy. (See my answer for Smarter filetransfers than rsync? for some clarity over this difference.)

The --partial flag tells rsync to keep and use any partially transmitted file as the target if the connection is interrupted for any reason. (Otherwise, a partially transmitted file is discarded.) The advantage of this flag is that time and bandwidth spent transferring a file is not wasted when the rsync is interrupted and retried. The disadvantage of this flag is that a file 90% transferred before interruption can end up being replaced with the same file only 10% transferred before interruption.

The --inplace flag tells rsync to build the destination file directly in place. This is often less efficient in time but avoids having two full copies of the destination file on the remote filesystem simultaneously. In the general case this flag should not be used (and indeed it conflicts with some other options such as --sparse).