Sunday, March 28, 2010

Backppc and the USB Drive

BackupPC is, well, "BackupPC is a high-performance, enterprise-grade system for backing up Linux, WinXX and MacOSX PCs and laptops to a server's disk." (BackupPC Website)

I have been using BackupPC at work for some time, but this is not about that. Neither is this about the advantages of BackupPC, of which there are several.

No, this is just a basic setup for backing up to a USB device.  This is my setup at home, with only a few PCs to backup.  This is not how I set things up at work.

So, here goes.

Becoming root
We need to become root for any of this...

#su -
or, for Ubuntu,
#sudo -i

Setting Up the Drive
Firstly we need to configure the backup device; in this case a 1TB USB hard drive. I plug in the drive. I run fdisk and create an ext3 partition.

Now I am going to mount this partition at /backup, and I am going to want to mount it here regardless of whether it appears as sdb1 or sdc1 or sdg1, or whatever. This can be achieved by adding a line to /etc/fstab, something like the following:

UUID=424b268a-8c03-4d5f-9718-f8b34a73d201 /backup ext3 defaults,noatime 0 0

This tells the system that the partition with UUID of 424b268a-8c03-4d5f-9718-f8b34a73d201 should be mounted at /backup, and that it is of type ext3. There are a number of commands that can be used to get the UUID of your partition. One of these is "blkid".

#blkid /dev/sdg1
/dev/sdg1: UUID="424b268a-8c03-4d5f-9718-f8b34a73d201" SEC_TYPE="ext2" TYPE="ext3"

Ok, so we've edited fstab, adding the appropriate entry.

#mount /backup

No errors? Excellent. Now to install BackupPC, assuming you've not already got it.

Installing and Configuring BackupPC
#apt-get install backuppc

Waiting while BackupPC is installed....

Now, we stop BackupPC, and copy the archive to a directory on the new partition.
#/etc/init.d/backuppc stop
#mkdir /backup/backuppc
#chown backuppc:backuppc /backup/backuppc
#rsync -a -H /var/lib/backuppc/* /backup/backuppc/

(The "-H" switch for rsync is important here.  It preserves hard links between files.  Hard links are used extensively by BackupPC)  

Edit /etc/backuppc/config.pl and change the "$Conf{TopDir}" line to match our new archive location. For example...

$Conf{TopDir} = '/backup/backuppc';

At this point you want to configure BackupPC to backup your computer(s). I'm not going into that here. Please refer to the documentation.

Running BackupPC
All done?
#/etc/init.d/backuppc start

There are a couple of things you need to be aware of with this setup.
  1. BackupPC cannot start if the USB drive is not mounted. Unless the USB drive is plugged in and switched on, expect BackupPC to crash immediately. This is not a big deal. This will do no harm. Just keep in mind that until you have mounted /backup and started BackupPC, there will be no backups.
  2. The drive should not be switched off or unplugged or unmounted while BackupPC is running.
  3. USB is slower than SATA. Backups will take longer.
  4. If multi-versioned backups are critical, you're going to want to backup to some kind of RAID device (Software RAID please. Using Hardware raid is counter-productive as you still end up with a single point of failure; the RAID controller).
The procedure to start BackupPC becomes
#mount /backup
#/etc/init.d/backuppc start
(Booting the system with the USB drive plugged in and switched on should also result in a running BackupPC system, as long as you don't specify "noauto" in /etc/fstab.)

The procedure for unplugging the USB drive should be
#/etc/init.d/backuppc stop
#umount /backup
... and now it is safe to switch off the drive.

Saving the Whales
Once backups are complete I shut down the drive and only switch it back on when it suits my needs - maybe every few days, sometimes weekly, thus saving electricity, and whales.   This is not so easy to do when using an internal drive for backups.

(Disclaimer:  This procedure may not, in fact, save any whales.  This procedure may even be harmful to whales, for all I know.  The author disclaims all responsibility for any harm which may occur to whales, or to your data, if you choose to follow the procedures outlined here.)

1 comment:

freelunch said...

Dear Sir

I have spent most of the evening following the procedure outlined above. It did not appear to do anything for my whales, though one of the bucks did become mildly irritated during the middle bit.

sincerely yours

etc, etc, etc