Backup a hard disk on Linux

If you would like to backup your hard disk, there is a simple way to do it by using “dd” command. The dd command utility is used to copy files or disk images from one location to another. Using dd, you can backup an unmounted disk as a (compressed) disk image which is then stored in a separate local or remote disk. Here is how to backup and restore a hard drive using dd command.

In order to use dd to backup a hard disk, you should unmount the disk first. A mounted hard disk may have various filesystem activities, and dd’ing such a live system may capture partial writes, which can lead to corrupted disk image. If the disk you want to backup corresponds to the root partition, you can boot from a Linux Live CD, and proceed to back up the root partition while it is not mounted. When a disk is unmounted, you can backup the disk as follows.

$ sudo dd if=/dev/sda | gzip -c > /mnt/disk1/sda.img.gz

The above command makes a clone of /dev/sda, gzips it, and stores the compressed image in /mnt/disk1. To restore the saved disk image, you can do the reverse:

$ gunzip -c /mnt/disk1/sda.img.gz | sudo dd of=/dev/sda

If you would like to backup a local hard drive on to a remote host, you can do the following.

$ sudo dd if=/dev/sda | gzip -c | ssh user@remote_host “cat > /mnt/disk1/sda.img.gz”

The above commands does disk cloning, compresses it, and then securely transfers the gzipped image to a remote host. To restore the disk image from the remote location, do the reverse as follows.

$ ssh user@remote_host “cat /mnt/disk1/sda.img.gz” | gunzip -c | sudo dd of=/dev/sda

For more advanced disk image backup/recovery options, check out Clonezilla.


Source : Xmodulo