Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are rsync operations atomic at file level?

I'm trying to figure out how if rsyncing files is atomic. I couldn't find any confirmation about it. Due to rsync being able to send only deltas, I was under the impression that it also updates only parts of the live files.

On the other hang DJB recommends rsync for synchronising live .cdb files and I've found this post ( http://lists.samba.org/archive/rsync/2002-April/002210.html ) which both would imply that the new file is created, then moved over to the proper location.

Can someone point me at an official source confirming one or the other?

like image 289
viraptor Avatar asked Sep 22 '10 12:09

viraptor


People also ask

Is rsync Atomic?

atom-rsync package. atom-rsync is an Atom package to sync files bidirectionally between remote host and local over ssh+rsync. Inspired by Sublime SFTP. This Atom package is a fork of the atom-sync package, which was abandoned around 2017 by the original author.

Why is rsync faster than cp?

rsync is much much better compared to cp because rsync copies whole files/directory only the first time. The next time when you use rsync command with the same files/directory, only new changes are copied to the destination folder, not the entire files are copied.

Does rsync go both ways?

rsync works in one direction, so we need to run it twice to sync directories in both directions.


2 Answers

Rsync creates a new temporary file which will contain blocks from the local (receiving) copy and whatever blocks it requires from the sending copy. When done the temporary file is moved into place replacing the original.

Full details are here;

http://rsync.samba.org/how-rsync-works.html

like image 77
Ira Cooke Avatar answered Oct 23 '22 13:10

Ira Cooke


No, rsync does not write files atomically.

During transfer, a hidden temporary file is being created within the same target directory (.[original-filename].[6-random-characters]) which contains the transferred file in its current state.

If you should happen to lose connection during transfer or rsync encounters any other problem, causing the connection to be closed, before killing the rsync process make sure to copy the temporary file in order to keep all the already transferred packages. You can simply rename the temp file (remove the leading "." and the trailing ".xxxxxx" to get the original filename).

like image 34
Gerald Avatar answered Oct 23 '22 14:10

Gerald