Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to be able to blindly back up my entire hard disk, so that I can blindly and automatically restore in case there is any problem.

I am not interested in merely backing up data, but specifically in how to backup everything, the entire linux operating system with all the configurations, etc.

In other words, If I had second computer with exactly the same hardware, how could I replicate the installation and all the data of the first one without having to install the operating system, configure things and so on?

I have made a full copy using rsync, so that it can be updated. Now, in case something happens again, how can I restore it? I have stored the MBR with dd as well.

share|improve this question
add comment

2 Answers

There're several ways to accomplish this, if you want an image of your complete installation and have a secondary hard disk (or a network location) as destination, then assuming your installation is on /dev/sda (in this example boot might be /dev/sda1, swap is /dev/sda2, root is /dev/sda3) and your secondary hard disk or network location is mounted at /mnt/backup

dd if=/dev/sda1 | bzip2 -9 > /mnt/backup/boot-image.bz2
dd if=/dev/sda3 | bzip2 -9 > /mnt/backup/root-image.bz2
dd if=/dev/sda count=512 > /mnt/backup/sda.mbr

You'll notice that swap is left out.

To restore the image, you'd boot using a livecd or similar, mount the backup location then run:

# caution this will erase /dev/sda
dd if=/mnt/backup/sda.mbr of=/dev/sda

At this point /dev/sda's partition, table should be restored & visible when you run:

fdisk -l

So you can restore with:

bzcat /mnt/backup/boot-image.bz2 | dd of=/dev/sda1
bzcat /mnt/backup/root-image.bz2 | dd of=/dev/sda3
mkswap /dev/sda2

Remove your bootable media, reboot and your system has been restored

However, it's often not preferable to image large filesystem because garbage in the free space will be included, I'd recommend you skip the steps for sda3 above and instead to backup use:

cd /; tar -cjf /mnt/backup/root.tar.bz2 / -X /tmp/exclude.txt

You would obviously first need to create /tmp/exclude.txt which should list locations to exclude from the backup, for example:

/dev/*
/proc/*
/sys/*
/tmp/*
/mnt/*

Then to restore from your LiveCD or whatever:

mkfs.ext3 -L root /dev/sda3
mkdir /mnt/restore; mount /dev/sda3 /mnt/restore; cd /mnt/restore
tar -xjvpf /mnt/backup/root.tar.bz2 

Or using rsync, in which case just create the filesystem & mount it as above & then rsync the contents back.

share|improve this answer
    
Great answer. I have two questions. First: unfortunately, I have no separate boot partition, but a single one where boot and / are, and a swap partition. But I have a copy of the first cylinder I did with: dd if=/dev/sda of=mbr_63.backup bs=512 count=63. Will it work if I restore that fist cylinder with dd (after that, fdisk -l should say the partitions are back, is that right?) and then I merely rsync everything back? –  Mephisto Oct 2 '13 at 13:51
    
Second question: Have you figured out this answer from scratch, or it is something you have already applied successfully? It is important to know that. If you are a beginning BOFH as your profile say, chances are that you have already restored cloned installations more than once. Is that the case? –  Mephisto Oct 2 '13 at 13:55
    
I've never backed up the first cylinder, so I can't speak to that. I would test the method before relying on it. You would also need to recreate the file systems before being able to rsync your data back. In answer to your question, I use a combination of the methods in my answer on a daily basis to create/backup/restore VM infrastructure. –  Nanzikambe Oct 2 '13 at 17:05
add comment

Your post is a bit confusing because you ask how to do it, but apparently want to use rsync. Instead, I'd recommend purchasing an external hard drive of adequate size, then cloning the system's disk drive to that hard drive. This is the fastest way I know to recover a complete system.

share|improve this answer
    
Rsync is done to keep the copy to date. What I want to know is how to restore it. –  Mephisto Oct 2 '13 at 13:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.