Imaging backup solution
Q I have been looking to set up a backup solution for some time now and have decided that I would get a external hard disk enclosure and new hard disk. I need an incremental backup tool like TimeVault or rsync, but I would like it to be imaging so that in the event of a hard disk failure I can get the boot sector, partitioning and all the rest of it back. I have not found any Linux software that does that yet, and I was wondering if you could help. My idea is that I can plug it in once a week and have some udev rules or something mount it and start a shell script that would call the app with the appropriate options. Then in the event of a hard disk failure or accidental deletion of a file I can roll back to a previous backup or if I get a bug in a script I've made I can get the old one version back. I would greatly appreciate it if you could point me in the right direction to such a tool.
A Incremental and imaged backups don't mix. An image backup is a copy of the disk, as you say, so by its very nature it contains everything. The most popular disk imaging program for Linux is Partition Image (www.partimage.org), which is most likely in your distro's repositories and also on many Live CD distros. The point about Live CDs is important, as it it not safe to make a whole disk (or whole partition) image backup while any filesystems on it are mounted read/write, as the data on the disk could change mid-backup, leaving you an inconsistent backup.
Your best bet, disk space permitting, is to use Partition Image to back up your whole disk once in a while, then use something like rdiff-backup to make incremental backups of your important data. Rdiff-backup keeps older versions of files, so it fits in with your requirement of being able to recover older or deleted files, whereas recovering individual files from a whole disk image is a much bigger job.
Unless you already have a spare disk of the exact same size, you may find that when your disk expires you want to replace it with a larger model, probably at a lower price than the old disk. In this case, you only need a backup of the Master Boot Record (MBR) and possibly the partition table. Create a backup of the MBR with this terminal command
dd if=/dev/sda of=mbr.img bs=446 count=1
This copies the first 446 bytes of the disk - the area that contains the MBR - to a file that you should store somewhere safe. You can restore it by switching the if and of (input file and output file) parameters. If you want to back up the primary partition table too, change the bs entry to 512. If you are going to restore to a different size disk, you'll probably want different partition sizes, so the best approach is often to back up only the MBR and create your new partitions from scratch. Now you can back up the contents of each partition with
tar czlf /path/to/backup.tar.gz /mountpoint
The tar options are: c to create an archive, z to compress it with gzip (use j for bzip2 compression), l to restrict the backup to one filesystem (so when used with / it stops the likes of /home and virtual filesystems like /proc being added) and f to create the archive in the named file. Do
fdisk -l /dev/sda >partitions.txt
to create a list of the disk layout, then store this along with your backups and the copy of the MBR in a Safe Place.
- Linux solution to automatically back up and restore hard drives
- Write backup script that only selects one file
- Choosing backup software
- Looking for a remote backup server
- Creating a backup email server on RHEL 4