Using rsync to back up my laptop
There are lots of good ways to back up your computer. I’ve used several. Lately, I am enjoying the ease, convenience, and quality of rsync. In typical geek fashion, I was perusing the rsync man page the other day and found some nice options that I hadn’t known about, so I started to experiment.
I wanted to back up my laptop to a portable, external hard drive, starting with a full backup, then going to incremental backups after that. I also wanted to make sure the backup was kept in sync with my local hard drive, but without accidentally permanently deleting anything from the backup that I might want or need later. Here is what I came up with, posted here mainly for the sake of my memory, but you might find it interesting as well.
First, to back up the entire hard drive, I need to do this as root. Since I am using Ubuntu, and because I like sudo, I just add that to the beginning of the command and enter my password at the prompt. This reminds me to mention that it is important that your backup be kept in a secure location, just as with your computer. Anyone with physical access to the backup drive will eventually have access to all your data.
Here is the command I used, followed by an explanation of the options I am using.
sudo rsync --force --ignore-errors --delete --delete-excluded --exclude-from=/media/disk/matthew-exclude.txt --backup --backup-dir=`date +%Y-%m-%d` -av / /media/disk/backup/matthew-laptop
Options used:
–force: forces the deletion of directories on the backup drive, even if they are not empty
–ignore-errors: tells –delete to go ahead and delete files even when there are I/O errors
–delete: deletes unnecessary or extra files from destination directories
–delete-excluded: deletes excluded files from destination directories
–exclude-from=/media/disk/matthew-exclude.txt: tells rsync not to backup files or directories listed in this file, which I include on the destination drive (my sample is below)
–backup: creates backups of files before deleting them
–backup-dir=`date +%Y-%m-%d`: creates a backup directory on the destination drive for those backups with today’s date as the directory name
-av: archive mode, which combines lots of great stuff together like preserving file permissions and ownership, and verbose output, which is nice for knowing what is going on
This is my exclude file.
home/lost+found/
home/.Trash-root/
home/matt/.thumbnails/
home/matt/.Trash/
lost+found/
media
mnt
proc
root/.thumbnails/
root/.Trash/
sys
tmp
That’s it. The first time I ran it, it took a long time. Of course, I have some 75 gigabites of data, so that isn’t surprising. After that, only things which have changed need to be transferred or deleted, so the process is quite fast.
17 comments April 8th, 2008
