Fetching contributors…
Cannot retrieve contributors at this time
190 lines (128 sloc) 6.13 KB

Ogden Area Linux User Group


Presenter:Seth House
Date: 2009-06-30


Backup strategies depend highly on the specific needs of the system and the user. There is no one-size-fits-all solution. Many talks on backups try to cover many situations; I’m only going to discuss one. This advice should suffice for most personal desktop usage.

Again, it is up to you to think through your usage and how your computer is set up in order to decide what works for you.

Jamie W. Zawinski, famous for work on Mozilla, Netscape Navigator, and currently maintains the XScreenSaver project.

“The universe tends toward maximum irony. Don’t push it.” — jwz

Where to Back Up Your Files

The backup method I’ll be talking about is as follows. Buy two external hard drives. I know, there’s plenty of other things I’d rather spend $120 on too — do it anyway. Copy your files to one of the drives every single day. Don’t forget — for the love of Pete, automate it. Keep that drive in your home. Copy your files to the other drive once a month. Take it to the office if you trust your desk space, or have a Backup Buddy and leave it at your friend’s house. (I’ll talk about encrypting your drives at some later date.)

  • Good: Keep a copy of your files on a separate partition.
  • Better: Keep a copy of your files on a separate disk.
  • Best:
    • Buy two external hard drives.
    • Copy your files to one every day; keep it in your home.
    • Copy your files to the other once a month; keep it somewhere not in your home.

What Files to Back Up

Generally, there is no reason to back up your entire disk. Decide what you want to backup by making notes as you build and configure your system. If you make a change to your system that was time consuming or hard to figure out, you’ll want to backup those changes. If your whole installation is stock, you probably just want to backup your home folder.

  • /etc
  • /var
    • /var/spool/mail
    • /var/logs
  • /boot/config or /usr/src/linux/.config
  • $HOME

How to Back Up Your Files

There are a plethora of backup utilities, some free some commercial. We’re going to talk about plain ‘ol rsync because it ships with every Unix everywhere.

Amanda, Bacula, rdiff-backup, TimeVault


Behold! The Power of rsync

We can replicate all the functionality of Apple’s Time Machine in a one line command. (Hyperbole much?)

How does this work? Well, we create an initial full backup of all your files. Then we run a cronjob every two hours and rsync compares your current files with the most recent backup, making hard links to everything that is the same, and making full copies of everything that is different.

Hard links have the following properties, given the file a with link b: the contents of the file are only stored once, so you don’t use twice the space; if you change a, you're changing b, and vice-versa; if you change the permissions or ownership of a, you're changing those of b as well, and vice-versa; if you overwrite a by copying a third file on top of it, you will also overwrite b.

This command works because rsync always unlinks before overwriting. This is referred to as creating rsync Snapshots.

We usually think of a file's name as being the file itself, but really the name is a hard link. A given file can have more than one hard link to itself--for example, a directory has at least two hard links: the directory name and . (for when you're inside it). It also has one hard link from each of its sub-directories (the .. file inside each one). If you have the stat utility installed on your machine, you can find out how many hard links a file has […].

—Mike Rubel,

What happens if you rm one of the links? The answer is that rm is a bit of a misnomer; it doesn't really remove a file, it just removes that one link to it. A file's contents aren't truly removed until the number of links to it reaches zero.

Want a GUI?

To restore the backed-up files, just copy them! Simple.

Apple’s Time Machine in one line:

0 */2 * * * BACKUPDIR=/var/timemachine/$USER;\
            rsync -a -delete\
            --link-dest=$BACKUPDIR/`/bin/ls -t $BACKUPDIR | head -1`\
            $HOME/ $BACKUPDIR/`date '+%FT%R'`

You have to manually create the initial backup with:

rsync -a $HOME/ /var/timemachine/$USER/`date '+%FT%R'`

Useful rsync Flags

Avoid crossing filesystem boundries.
Do not sync any files or directories that match a pattern or path.
Don’t make any actual changes to the filesystem.
Resume partially transfered files and show a progress meter.

rsync -a -delete --link-dest=$BACKUPDIR/`/bin/ls -t $BACKUPDIR | head -1` $HOME/ $BACKUPDIR/`date '+%FT%R'`