
Backup Ubuntu using PartimageCreating a baseline backup of whole partitions need not be difficult... more like essential.
First, some words of advice: never underestimate the need for a backup copy of your system and data, because you never know when you'll lose a hard drive from an electrical spike, a fire, a flood, a burglary, or from some idiot dropping a heavy object on the computer case while the hard drive is writing -- who, me? Err...yes. Fortunately, my backups were secure. I had disk images of system and data partitions as a baseline, and incremental backups covering known restore points, so I needed to rescue only a few days of data. Please excuse my smug statement. I've been doing this awhile, but with That-Other-Operating-System-From-Redmond®™©™. Getting organized in the brave new world of Ubuntu isn't difficult, but does take preparation and planning.
Just DD
There's a native command in every Linux distribution simply called dd, short for disk dump. It clones the source partition block-by-block.
It's a very low-level, command-line, disk utility, for which the right syntax is crucial. If you mess up and accidentally misquote the source and target, you could wipe out everything you're trying to backup and more besides. Just for a laugh, try typing dd -help into a terminal. What you get is the manual page.
Go for it if you want to--I've got another thirteen pages of instructions and I'm still not confident.
So not dd, then...
Sticky, sticky tar
I've been able to perform adequate backups using tar.gz from the command line, but the syntax to include and exclude all the relevant stuff for my system partition looks like this:
sudo tar cvpzf 710bu010408.tgz --exclude="/proc/*" --exclude="/lost+found/*" --exclude="/dev/*" --exclude="/mnt/*" --exclude="/media/*" --exclude="/sys/*" --exclude="/tmp/*" --exclude "/var/cache/apt/*" --exclude="/ext3_data/*" --exclude="/vmdata/*" /
If it all goes wrong, I've got the whole file system,
but no boot record or bootloader to restore. I still need to boot up to
a terminal to un-tar the whole thing. Therefore, I would like to have
some tools, preferably on a boot disk, with a guided interface that can
image and restore the partition so that I don't screw up or miss out on
anything. I happen to have such a tool: it's the Partimage application present on a bootable disk named Parted Magic.
Tools for a Magical Rescue
Fortunately, we have a choice of utility CDs; SystemRescueCd (project at http://www.sysresccd.org/) is a 170MB download of a bootable ISO CD-ROM. To quote from the project wiki: "SystemRescueCd is a Linux system on a bootable CD-ROM for repairing your system and recovering your data after a crash."
My current favourite, however, is Parted Magic (project wiki at http://partedmagic.com/wiki/PartedMagic.php), a small--under 40MB--CD-ISO download, which I first picked up for a disk-rescue tool.
Both boot CD's contain the Partimage tool for creating our baseline images.
Partimage: does what it says
What it says on the project wiki is: "Partimage is a Linux utility which saves partitions...to an image file." Run it from the Parted Magic disk, which boots a complete Linux kernel into memory so that you can work on your hard drives in safety. Features include:
- support for most Linux and Windows file systems (dual-booters can smile here)
- image file can be compressed with gzip/bzip2 to save space on your backup media
- image files can be split into segments to be copied on CDs/DVDs
- imaging across networks using Partimage network support, Samba, NFS
Nothing Like a plan
Two ground rules you should set before you start:
1. Make sure you know all your partition names, mount points, labels, sizes and free space so that you don't get confused under Partimage -- you'll see why soon. I screen-dumped the File-Systems tab from Gnome System Monitor as it lists the mounted names. Alternatively, you could run Parted/GParted or save the text file generated by the List Partition Tables utility on the Parted Magic CD.
In my case, I'm backing up /root, /home and /usr which is my baseline for my Ubuntu system. So that's SDA1, SDA6 and SDA7. Nearly all my data files live on the other Windows/NTFS, ext3 and vmdata partitions that I backup separately. I needn't worry about the swap partition because I'll create a new one when I do a restore.
2. My opinion: Don't image your hard-drive partitions while they are mounted. You want no writing to, or deleting from, the disk while creating the partition image - not by your host operating system, any of your applications, or yourself. Boot from the live-CD and run the tools from there. Partimage doesn't need anything creating, moving and deleting files and folders while it attempts to create a true snapshot.
In true Columbo-style, 'just one more thing'...
Before backing up: make sure your target drive for storing image files has properly allocated read/write permissions, otherwise Partimage will give you a cryptic message when it can't write its temporary files on starting the backup.
Parted Magic Tricks
Hitting F12 during power on should give you a one-time boot menu so you can select Boot from DVD/CD. On boot-up, Partition Magic gives you a neat, clutter-free, Xfce desktop, a single icon panel and slide-up menus for all the tools.
Mount/Unmount partitions
I start by firing up the Mount Utility, first to make sure none of the source partitions (to be backed up) are mounted, and second so I can mount the destination partition for Partimage to write its backup images! You tick the box for each item to mount/unmount. Some versions of the Mount Utility close on clicking the OK button without confirming completion. In the screenshot, I've relaunched it to discover the full mount point it assigned to my slow-but-reliable USB hard drive.
Yes, you can mount everything manually in a terminal if you really want to.
At last - create partition image
Open a terminal session and enter partimage. It's a
character-mode application, so you move around with arrow and tab keys,
not with a mouse. The spacebar changes values in option lists; the
active choice is marked with an asterisk. This layout works and guides
you through the process.
Set the partition to save/restore.
This is where you need to know your partition details. Since I've got
/home and /usr on identical 6GB partitions, I need to identify which is
which when I backup and restore. Be alert to the fact that Ubuntu
called my (internal) source partitions SDA# while Partimage used HDA#
for the source and SDA# for the (external) destination USB drive!
Thankfully the identifying number is the same. It's easy to be confused
about the partitions - not because of the software, but from operator
error.
Set the image file to create/use.
You need the full path, including the device, root and target folder as well as the backup file name. Type carefully and proof-read before you move on. Spaces and punctuation characters in the name should be avoided.
Action to be done: defaults to Save partition to a new image file.
Connect to server, IP/name and Port number are only for backing up across a network. Otherwise, leave these blank. You will need appropriate user logon, password and write-permissions for network drives-Partimage will prompt you for them when it begins.
Tab onto the Next option or press F5 key to move onto the next screen.
Compression Level: The guidelines are sound. "None" means no compression, so you need a backup drive with space equivalent to used space on your source partition. I take this as a general rule, as compression ratios vary according to the contents: .doc and .odt files compress well, .jpeg and .avi may not compress at all. Keep some free space for contingencies.
Image Split: Automatic is fine if you know you'll span several disks and expect a prompt to change media.
File size: I always keep the default
value because it's easier to manage portable 2GB segments with it.
Also, if I get a read-error in one segment file I may still be able to
salvage the rest.
Continue with F5 key again.
Partimage will confirm back to you what you've chosen.
OK this to continue.
If you chose to Check Partition before backup, you get the information pane
OK this to start the backup.
You will get a progress bar with elapsed and estimated time to complete. Writing to my old USB drive is slooow.
You get completion status at the end of the backup.
Quick Guide to DVD backups
It is possible to write directly to DVD+R and R/W disks (DVD-R are problematic, apparently). Mount the DVD-drive first, then in Partimage,
- set path for the image file to the DVD writer;
- clear the "check for free space" option;
- set the size of backup file segments to a safe multiple to fit on DVD, such as 1.5GB (3 segments to a DVD);
- set it to "pause on volume changes" so you can swap in empty DVD's as they fill up.
Restore a disk image
Important-Before restoring, make sure your replacement drive is in a fit state to boot a restored image. Partimage does not cover the master boot record (MBR) and bootloader. If you intend to restore to a brand new hard drive, you need additional tools to save and load your MBR, partition tables and a bootloader (all material for a separate How-to, but in the meantime, there's a useful guide in the on-line Partimage manual at http://www.partimage.org/Partimage-manual_Backup). For this How-to, I cheated slightly: I installed a scratch-instance of Ubuntu 7.10 from the live CD with custom partitions matching my old ones. This verified that my new drive was working within 20 minutes, complete with valid MBR and GRUB bootloader. The rest will be overwritten when I run the Partimage restore.
The restore process works much the same as the backup. You need to select the "Restore partition from an image file" option and identify your image file from the backup drive, mounted with read permissions. You should have your destination drive prepared with a target partition of equal or greater size to the uncompressed size of your image contents (I'll not go into creating and resizing partitions here either). Partimage will obliterate existing data on any destination partition, so check your settings before you commit to a restore!
Before you reboot, make sure you have a valid Linux swap partition somewhere on the drive. GParted on the Parted Magic CD can create this.
Confidence
Best of all, I know this works. I picked up a spare
hard drive for the laptop for another project some time ago. I swapped
out the main drive, put in the spare and booted the Partition Magic CD.
Launching Partimage, I restored SDA1, SDA6 and SDA7. I rebooted and was able to log on to my regular Ubuntu desktop. Result: 100% confidence in my base backups.
Now, what to do about the incremental backups...?
Next month Stephen Bant will take things a step further and use Mutt to have backups automatically sent, as an attachment, to an email account.










