Are rsync operations atomic at file level?
Asked Answered
D

3

20

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?

Dower answered 22/9, 2010 at 12:40 Comment(0)
C
21

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

Chromate answered 1/8, 2011 at 20:8 Comment(4)
You didn't answer the actual question. – Would this mean that the updating of each individual file is atomic?Seleucid
Yes if you consider a file move operation within the same directory to be atomic.Chromate
"Consider"? Atomic vs non-atomic should be a matter of fact, not opinion, I think? :) Do you mean to say that there are instances where renaming of a file in a directory (on a local disk) is not atomic? If so, when would that happen?Seleucid
@zrajm: yes, that depends, see even here for more fundamentally asked a yes and no answer: https://mcmap.net/q/334232/-is-rename-atomic/367456Falconet
K
2

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).

Kerriekerrigan answered 1/9, 2017 at 2:28 Comment(0)
C
1

There is a perl script that is supposed to add this functionality: http://www.opensource.apple.com/source/rsync/rsync-40/rsync/support/atomic-rsync

The problem is that I tried to test it and it doesn't work. Also there is something strage because from the URL it looks like being something related to rsync 4.0 and the current version of rsync is 2.6.9 !

Cambodia answered 28/7, 2011 at 14:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.