How to use dd and ddrescue to back up your data
A few months ago we looked at duplicating partitions as a way to back up your data. A number of readers have expressed an interest in knowing more about this, so I’m going to look at it in a little more detail this month.
As a reminder, we used the ‘dd’ and ‘ddrescue’ tools to perform a cloned image backup, and the ‘partimage’ tool to create a special image format. The difference between the two types is as follows: the first copies every single byte of raw data from the hard drive’s partition, thus creating a backup image of exactly the same size; the second copies only the used data from the partition and then compresses the result, leading to a much smaller file.
With the first method, the type of filesystem you are backing up is irrelevant, as a duplicate of the original is made. With the second method, the partimage tool must be able to understand the filesystem used on the partition in order to extract and back up only the used data.
The ‘dd’ and ‘ddrescue’ tools will copy data from any source to another, byte by byte. This could even be a single regular file, thus doing the same job as running the ‘cp’ command. Linux and other Unix-based systems treat everything as a file, and so a partition, or indeed a whole hard drive, can be duplicated in the same way. It is therefore possible to clone a hard drive, either as a backup, or to use the second drive in another machine. An example command, one you should not enter yourself, is:
$ sudo ddrescue /dev/sda /dev/sdb
We are using the ddrescue command instead of dd, simply because it does everything ‘dd’ does, but shows more information about progress and errors, and is more resilient. You can install this command in Ubuntu by running:
sudo apt-get install gddrescue
Running this command will copy every byte from the drive found at /dev/sda to the one at /dev/sdb. It makes sense therefore that the second drive should be an identical model to the first, as every byte, even those that are untouched, and not even in a partition, will be copied across to the second, overwriting whatever is currently there. The duplicate will boot just like the first, with every file and operating system intact. An installation of Windows will boot too, though be aware that it can lead to activation problems; there will be no such issues with Linux.
The usual method of backing up in this fashion is per partition. This is where the choice of ddrescue or partimage comes in. Where space is no issue, or the filesystem to back up is almost full, ddrescue is probably the wiser and simpler choice. It is guaranteed to work on any filesystem as a fail-proof backup that can easily and very quickly be restored.
However, one particular advantage of partimage is for freshly installed and configured operating systems. For instance, if you have just installed a copy of Linux with all the updates your partition will probably only be using two to three gigabytes. You can make a clone of the partition with partimage, taking only a couple of gigabytes of disk space on another partition or drive, so that if you later decide to reinstall the operating system, you can go straight back to this fresh installation image. You could even write out the image file onto a blank DVD.
Partimage works with any Linux filesystem and Fat 32. For Windows installations using NTFS, which is almost any since Windows XP, an alternative to partimage, ntfsclone, is required. This is a command-line tool that performs the same job it creates a special image of only the used data, which can then be restored back. An example of this command is:
# ntfsclone --save-image -o backup.img /dev/sda1
Related articles
St Helena, a 'small British village' in the mid-Atlantic, is seeking support and funding for a broadband connection
A technology for downloading files. Allows even very large files to be downloaded quickly.
|
|
|
|
|
Computeractive Excel (2010) Online tutorialPrice: £19.99 |
Computeractive Word (2010) Online TutorialPrice: £19.99 |
Computeractive Powerpoint (2010) Online TutorialPrice: £19.99 |
Angry BirdsPrice: £9.99 |
Back Issue CD-Rom 14 (2011)Price: £15.99 |