rsync --backup is non-atomic -- does it need to be?

JD Paul jdpaul at
Fri Jul 27 14:36:30 MDT 2012

It appears that 'rsync --backup' is non-atomic.

The code in question is in backup.c, in make_simple_backup():

  64         if (do_rename(fname, fnamebak) == 0) {
  65             if (verbose > 1) {
  66                 rprintf(FINFO, "backed up %s to %s\n",
  67                     fname, fnamebak);
  68             }
  69             break;
  70         }

This has a race condition because 'fname' will be gone until the
rename() from the temp file happens.  It's a small window, but I've
seen it get tripped.

Is there some deep reason to NOT do

 	do_link(fname, fnamebak);

instead of the do_rename(), so that fname never disappears, and is
updated atomically?

(This is, of course, not actual code; it requires error checking,
verbosity, and a judgement call on what to do about a backup file that
is not unlink()-able.  I figured I'd ask about the underlying logic
before attempting a patch.)

Thanks --

 					JD Paul

More information about the rsync mailing list