I was wondering if there is a way to tell rsync to only apply changes (delete, overwrite, create) only if all files in the file list transferred successfully.

Just to clarify, this would essentially be putting a transaction around the transfer.


you could use a filesystem (btrfs, zfs) with snapshot-features:

  • snapshot your current state
  • rsync
  • check exit code of rsync and rollback if needed

you can also enroll your own snapshots:

  • make a copy of the files (this becomes the working area)
  • rsync to the working area
  • check exit code of rsync and move working area over the original files if exit code was ok.
  • Instead of copies, you may want to use hard links to save time and space. – Ryan Thompson Nov 15 '10 at 4:12

You could use the --delay-updates option, or if you want really atomic updates, the atomic-rsync script (included in Debian as /usr/share/doc/rsync/scripts/atomic-rsync.gz).

  • I'm actually using the --backup option now and checking to see if the rsync fails. If so I attempt to restore the backup. Nothing much you can do if the network craps out and you can't connect to restore the backup. Pretty small chance though ;) – Tres Nov 18 '10 at 10:57

From the 'rsync' man pages, you may be in luck only for deletes:

Some options require rsync to know the full file list, so these options disable the incremental recursion mode. These include: --delete-before, --delete-after, --prune-empty-dirs, and --delay-updates. Because of this, the default delete mode when you specify --delete is now --delete-during when both ends of the connection are at least 3.0.0 (use --del or --delete-during to request this improved deletion mode explicitly). See also the --delete-delay option that is a better choice than using --delete-after.

  • That would satisfy deletes, however, I still need it to work for all files just in case there is packet loss or connection interruption. Great answer though. Thanks. – Tres Nov 16 '10 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.