2

I made a very simple backup script using rsync that backs up some folders to an USB stick. This is just for quick daily backups.

The command is

rsync -av --delete

followed by --exclude options and the paths.

But now it occurred to me that this is possibly not safe:
What happens if my hard drive gets corrupted, and some files can not be read anymore? Will rsync delete the files on the stick if it can't read the source?
Or more generally: Is there any scenario other than "me deleting the files on my hard drive" that will lead to deletion of the files on the USB stick?

  • why you don't use a real backup program (like some of these here) and not just a simple synchronization program?!? – DJCrashdummy Nov 12 '15 at 13:14
  • There are different reasons, like being able to access the backup from any computer, and because it takes just one click and a few seconds, but mainly because I love simple and flawless things :) I also make disk images once every 2 or 3 month. – alain Nov 12 '15 at 15:41
2

First of all, --delete option can lead to some unwanted destructive results if you are unaware of the background. For example, if the source becomes empty then all the existing files at the destination will be removed or if some files are removed from source then those files will be removed from destination too.

What happens if my hard drive gets corrupted, and some files can not be read anymore?

If rsync can not read the source, it would show a permission denied message and won't do anything further. So your existing files at the destination will be safe.

Is there any scenario other than "me deleting the files on my hard drive" that will lead to deletion of the files on the USB stick?

Unless your USB itself gets corrupted, no, there is no scenario where (you don't remove files from source, the hard drive and) the existing files on the USB will get deleted by rsync with --delete option.

Test:

% ls -1 source dest
dest:

source:
foo

% rsync -av --delete source/ dest
sending incremental file list
./
foo

sent 143 bytes  received 38 bytes  362.00 bytes/sec
total size is 16  speedup is 0.09

% ls -1 source dest              
dest:
foo

source:
foo

% chmod 000 source 

% rsync -av --delete source/ dest
sending incremental file list
rsync: change_dir "/source" failed: Permission denied (13)

sent 20 bytes  received 12 bytes  64.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0]

% ls -1 source dest              
dest:
foo
ls: cannot open directory source: Permission denied
| improve this answer | |
  • Thanks, that's what I wanted to know. Do you have a reference for "If rsync can not read..", or is there an easy way to verify that? – alain Nov 11 '15 at 23:31
  • @alain Please check my edits.. – heemayl Nov 11 '15 at 23:37
  • Perfect, thanks. I also tried with chmod 000 source/foo to be sure, and foo is still in dest. – alain Nov 11 '15 at 23:49
  • @alain If you have 000 in a directory, no one can read the files inside that because directory contains the mapping between filename-inode of all files inside that directory.. – heemayl Nov 11 '15 at 23:51
  • I'm not sure what you mean; I tried with an unchanged source dir and just changed the permissions of the foo file. Is this correct to simulate an unreadable file in a readable dir? – alain Nov 12 '15 at 0:00
1

An easy solution to corruption and deletion concerns is to employ a proper backup procedure. Rotate a series of three (or more) USB thumbdrives, using the eldest 'backup' as the plugged in stick when you run this command once every week. This way if you catch the corruption before you cycle through your USB drives, you can recover from it. This is known as FIFO (First In, First Out).

There are other, more complicated schemes out there, all of which are compatible with your backup method. A primer on some of these is available on Wikipedia at the following link:

https://en.wikipedia.org/wiki/Backup_rotation_scheme
| improve this answer | |
  • I think I will make a rotation scheme with weekday folders on the USB drive, if there is enough space, because this will help if I want to recover a file that I deleted. – alain Nov 11 '15 at 23:55
  • Another thing you might wish to consider (if you upgrade from USB drives to a large external hard drive) is using version control software. You 'commit' your changes and it tracks the lifetime of the files in question (neatly avoiding the 'what if' for corruption and deletion as well as providing a way to recall any of the past versions as necessary). A summary of this approach (though they don't touch on the use of backing up a machine in this fashion) can be found here --- biz30.timedoctor.com/… – Aren Nov 12 '15 at 1: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.