Creating Bootable Backups in Linux13 Mar 2015
They said it couldn’t be done, but it has been. After searching for “Create bootable backup CentOS 6”, digging through forums and getting trolled in IRC, I finally got my backup to boot. On freenode, the people of #centos laughed at me, saying that Backups weren’t meant to be bootable. You can’t get redundancy and backups from the same disk. On the CentOS forums, they were saying the same thing:
Centos Backup help
Postby pschaff » 2011/11/22 22:26:38 You can’t get there from here.
There is no reliable method to do an on-line full image backup suitable for a bootable system recovery. Open files will not be properly backed up. If you “clone” the system to disks that are still on-line then you are likely to encounter problems with disk labels, duplicate LVM volume labels, and/or UUIDs. Your best bet is probably to use the additional disks for backing up your valuable data.
However, I wasn’t using LVM and I don’t intend to for a while. Although, this same process could work with LVMs using some additional steps, but I won’t go over that in this post.
No matter what they said, no matter how bad of an idea it seemed, I trudged on and with the help of my favorite co-worker AJ, we got it working.
We were able to successfully clone one disk to another, on a live system, without doing a block-level copy (like with
First, you’re going to need this set of little perl scripts I like to call nsync.
This is what we’ll use instead of the traditional rsync command. Hats off to Carl Flippin for writing the original version of this script.
So, let’s clone the current partition layout from
/dev/sda to the backup drive
partprobe to make the OS recognize the new partitions.
Then, make sure the disks have matching partitions by running
fdisk -l. You should see something like this:
Now we need to create mount points for the new drive before we copy everything over.
Since we have three partitions,
/home, we’ll mount them all under
Then, mount the partitions:
Now that the drives are mounted, we may as well make the pseudo-filesytem directories that we won’t be copying anything to:
Now, we’re ready to use
nsync.pl to sync the disks. Create the file
/etc/nsyncexcludes.conf and put in it all the directories you do not want sync’d. We definitely don’t want to sync
/sys of our live system, so make sure you at least add those three directories there.
Once nsync completes, you can actually mount the live system’s
/proc folders and
chroot into your backup disk to test that everything is working:
You should be able to run
yum update or
yum install [package_name] or whatever else you can do on your live system.
Booting off the Backup Disk
You will need to install grub to
/dev/sdb in order to boot off the backup disk, and you’re going to need to edit
/etc/fstab and make sure the UUID of the main drive is not listed. Instead, you need to use
/dev/sda to specify your partitions.
You’ll then need to edit
/boot/grub/menu.lst, for the same reasons. The part you’re looking for is
root= which is usually where you’ll find the UUID of your root partition. Change that to
/dev/sdaX where ‘X’ is the number of your root partition.
Once that’s all done, you should do one last thing to ensure SELinux doesn’t freak out on you.
Now you should be able to swap the disk
/dev/sdb in place of
/dev/sda and boot from your “backup” drive.