Monday, December 24, 2012

Backup with rsync

You have a number of options if you wish to protect your Ubuntu system against the unlikely event of a disk crash. I use a layered approach to save my precious files and memories. There are numerous cloud providers that will give you some free space to store your files: Ubuntu 1, DropBox, Google, and Amazon to name a few. None of them provide enough space to save my music, pictures, videos, and game files.

To save those drive eaters, I have two external drives use as redundant storage. The cloud providers save the documents I work on day-to-day while the external drives save files I add but seldom, if ever, change. I try to perform the backup on a monthly basis.



My favorite command for the backup is rsync. As its name implies, it syncs files from one location to another. The nice thing about rsync is that it ignores files that are the same between the source and destination directory. Thus once a file is copied, it isn't copied again. This is a great time saver over a simple cp command.

The base, recommended syntax is


sudo rsync -azvv /home/path/folder1/ /home/path/folder2


This will sync the files from folder1 to folder2, recursing into all sub-directories  and compressing the files as it goes. If you add a --delete, the command will delete files in folder2 that no longer exist in folder1.

The sudo is there to make the command run as a root (super) user. This is important as it will resolve any potential permission issues with reading the files.

I use a slightly different version since I'm going to an external drive. I use -avv, choosing not to compress. I also use the --exclude flag for a few directories, like the browser cache, that are temporary in nature. I exclude the .gvfs file as well. If you don't you'll get an annoying error message that is of no importance.

To make the command is correct, use the --dry-run flag which will simulate a run without moving any actual files.

So, my steps for backup are (substitue your own directory names)

  1. plug in external drive
  2. open up a terminal window
  3. cd /home
  4. sudo rsync --dry-run --exclude=.cache --exclude=.maptool --exclude=.gvfs -avv /home/rkathey/ /media/Athey500/rkathey > t.out
  5. check the file t.out to make sure everything is there and looks good
  6. sudo rsync --exclude=.cache --exclude=.maptool --exclude=.gvfs -avv /home/rkathey/ /media/Athey500/rkathey > t2.out
  7. check t2.out for any problems.
If you want a warm, fuzzy feeling while running step 6, either exclude > t2.out from the command above or tail -f t2.out from another command window. I prefer the tail -f command so I have a history of what was transferred.



Note that if you shy away from the command line, you can also install Grsync from the Ubuntu software center for a graphical interface. The interface looks pretty simple and it claims to simply wrap the standard rsync command with a gui. Note: I have actually tried this program.


It's no coincidence that pictures are one of the few items that people decide to save before anything else during a disaster. In today's digital age, most photos and other important information resides on our computers. Having a good backup plan is like insurance - it brings peace of mind even if you hope you never need it.  

Happy Backuping,
Zack's Dad

p.s. Merry Christmas

No comments: