LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (http://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Copy an internal hard drive as backup? Restore an internal drive? (http://www.linuxquestions.org/questions/linux-hardware-18/copy-an-internal-hard-drive-as-backup-restore-an-internal-drive-648370/)

Peufelon 06-10-2008 05:28 PM

Copy an internal hard drive as backup? Restore an internal drive?
 
I have a desktop computer which has an old Mandriva install (actually, Mandrake 10.0 with 2.6.3-7 kernel). This computer has a 40 GB internal hard drive (Western Digital). Since the install is rather old, I am concerned that I might not be able to reconstruct it from the installation disks (especially since something seems to be wrong with one of them!) if the hard drive ever failed.

Nightmare scenario: the hard drive fails and although I regularly back up personal files to CD, I find that I am not able to reinstall all the software (e.g. due to conflicts with the older software I need with currently supported software).

A little late in the game, I'd like to copy the entire drive to another hard drive, using the unix command dd (or another if more appropriate), so that I have a backup.

Can I copy the conents of the entire 40 GB drive to another hard drive (including the master boot record, the boot loader, the operating system, and all the contents of /bin and so on), store that somewhere far away from any magnets, and have a reasonable expectation of being able to replace the orginal drive with a new 40 GB hard drive if/when it fails, copy the backup to the new drive, and be able to boot up normally, and (after updating personal files from CD backup) to be able to get back to work?

What about copying to an external hard drive? The ones I've seen are much larger than 40 GB. If I tried to copy a 40 GB drive to a 160 GB drive, is the worst that can happen that I waste a lot of space? What about copying from the 160 GB drive back to a 40 GB drive?

stress_junkie 06-10-2008 07:27 PM

This is not so difficult. I use tar for my routine backups on my systems. If I want to make a restore disk that includes several operating systems then I use a rescue cd distribution (System Rescue CD) and partimage.

Let's say that your system is installed on /dev/hda1 and you have an external hard disk on /dev/sda1. Let's also say that you already have a mount point at /mnt/backup and that you encrypted the external partition with True Crypt. This is what I do.

First I mount the external disk partition on /mnt/backup.

Second I make a backup of the system disk's Master Boot Record using dd. If you have logical partitions you will also need to use sfdisk, which I will include in my example. These copies of the MBR and partition table are written to the / directory in files named <date>-hda-mbr.dd and <date>-hda-partitions.sfdisk.

Third I use tar to make a backup of the / file system storing the archive file in /mnt/backup/<date>-rootfs.tgz, using the --one-file-system parameter to prevent tar from backing up the contents of /mnt/backup et. al.

Code:

truecrypt -t /dev/sda1 /mnt/backup

dd if=/dev/hda of=/`date +%F`-hda-mbr.dd bs=512 count=1 conv=notrunc,noerror

sfdisk -d /dev/hda > /`date +%F`-hda-partitions.sfdisk

tar czv --one-file-system f /mnt/backup/`date +%F`-rootfs.tgz /

Of course if you don't use True Crypt to encrypt /dev/sda1 then you can just mount that partition using the mount command.

Using partimage is also pretty easy. I boot a CD containing System Rescue CD. We need to do this because partimage won't back up a mounted partition/file system. Partimage is particularly good if you have a dual boot system and you just want to get a snapshot of your systems before viruses or misconfigurations begin to accumulate in your operating system.

Boot System Rescue CD.

Run partimage.

The menu is pretty self explanatory. The only caveat is that you cannot use bz2 compression if you want to be able to retrieve your MBR and partition table from the partimage backup. In all respects the partimage archive is comparable to a Norton Ghost archive. It contains the files and the MBR and the partition table. It does not copy empty disk blocks. If you want to put the archive files on CD then you may want to limit the archive file size to 2000 blocks. Then if the backup requires more space partimage will create more 2000 block archive files.

I have used both of these methods to restore systems that I have backed up. Both methods are reliable. Partimage is a little bit less trouble to restore. After all, remember that with the tar archive file the disk partition information and MBR are inside the archive file. You have to extract them from the archive file in order to use them, then restore the archive file to the new disk, so it is one extra step to recover the system. On the other hand the tar method is quicker to do and you can perform a tar archive backup while the system is running. You can't do that with partimage.

:)

mtb 06-15-2008 04:28 PM

I have used clonezilla and i have found it really good. It's a live distro designed to backup and restore.

But i don't know what happens if you want to restore a 40gb image on a 160gb hd. Sorry.


All times are GMT -5. The time now is 02:34 PM.