rsync for backup but don't want to wipe ( not erase ) drive

I am not sure how to even ask this question without explaining. Say I use rsync to backup drive-a to drive-b. Drive-a fails and all data is lost when the rsync went off it saw that drive-a had been erased so it erased drive-b.

I am trying to write an rsync script so this does not happen. this actually happened to someone I knew so it is possible.


Solution 1:

In the scenario you described (failed source drive), rsync will not delete anything, because:

  1. by default, rsync does not delete anything until you pass it the "--delete" option
  2. even passing it the "--delete" option, rsync will not remove a destination file if the source disk can not be accessed. From the man page:

If the sending side detects any I/O errors, then the deletion of any files at the destination will be automatically disabled. This is to prevent temporary filesystem failures (such as NFS errors) on the sending side causing a massive deletion of files on the destination. You can override this with the --ignore-errors option.

The only means to end up with a wiped target after source failure is to:

  • mangle with advanced rsync options (see man page)
  • have a source failure that present a seemly consistent, but empty, filesystem (which is a very rare possibility)

Anyway, I second the suggestion to use rsnapshot + hard links. I use this setup for backup purpose and it is very convenient.

Solution 2:

Basically, this "someone you knew" probably ran this command with rsync:

sudo rsync -av --delete /src /target

Although, this is highly unlikely unless, maybe, he added the --ignore-errors option.

In any case, if you only consider source drive as possible failure you are missing the point of backup. Nowadays, the cloud is your friend.

To answer your question, the best possible solution you could use to avoid drive failure deletion on target with rsync would be to use -b with --backup-dir=DIR options for an incremental backup. Example:

sudo rsync -avb --delete --backup-dir=/backup/incremental /src /target

Above, original /target files, that are to be updated, are copied to /backup/incremental before the update process. Files deleted on /src that are now targeted for deletion on /target are simply re-named and placed in /backup/incremental.

Consider your first command with rsync to be a hard copy with -n = --dry-run option:

sudo rsync -avn /src /target