Simple clear advice in plain English

Hands on: Linux disaster recovery

Quick and efficient backup methods – and what to do when it all goes wrong

The time you come to realise just how dependent you have become on your computer is when things go terribly wrong. Your partitions won’t mount, your files seem corrupt or, worst of all, your entire hard drive seems to have become unreadable.

The first and most obvious piece of advice, as anyone would tell you, is to make regular backups. It is surprising how many people who have years worth of valuable files have few or none of them backed up.

Here we will look at some preventative measures and – in case bad things do happen – some tips for disaster recovery.

Simple backups
rsync is a really useful tool for duplicating files quickly and with minimal fuss. The duplicate files it creates can be ‘synced’ at any time, so only changed files will be copied over. This method is good for regular backups, where you are protecting yourself more from accidentally deleting files or finding an older version of a file. To copy the directory ‘documents’ to /backups you could run:

$ rsync -av documents /backups/

With this command rsync will use the archive method (-a), which preserves all of the files’ original attributes (including permissions, date modifications and so on), and will recursively copy the directory (including the documents directory itself) to /backups. You could run this command weekly to maintain a regular copy of your files.

Rsync was designed to work well over a network. If you have OpenSSH set up on both machines, just include the machine’s name before the directory, for example:

$ rsync -av documents myserver:/backups

Partition backups
An alternative to copying individual files and directories is to make a raw copy of an entire hard drive or partition. This is easily performed in all forms of Unix (and OSX) using the standard ‘dd’ command. What this does is to read raw bytes from any file (including devices) and to copy them back to any other file or device. Since only raw bytes are being read, the dd command doesn’t need to understand the layout of the data at all, so this method works with any kind of filesystem. For example, /dev/hda1 is a 5GB partition and contains a Linux ext3 filesystem:

# dd if=/dev/hda1 of=image.ext3

The dd command now reads every byte from the partition and copies it to a file called image.ext3 in the current directory. This is an exact clone, so copying back the file to the partition would return the data to the precise state it was in when the backup was made:

# dd if=image.ext3 of=/dev/hda1

You can duplicate an entire hard drive in this way. If you have two hard drives of exactly the same size, one on /dev/hda and the second on /dev/hdb, copying every last byte can be done the same way:

# dd if=/dev/hda of=/dev/hdb

A severe word of warning: be very careful when using the dd command. A mistyped command can result in a complete loss of data. If you accidentally entered /dev/hda2 on the second command, your backup would be restored to the second partition instead, completely overwriting whatever was there previously, and without any warnings.

More efficient cloning
While dd is found on every Unix and Linux system and is a reliable way to back up your data, it has a major disadvantage for general use: every byte must be duplicated, whether it contains any valid data or not. If you want to back up a 100GB partition where only 20GB of the space is in use, you will still need 100GB of additional space to clone the data.

Partimage is a useful open-source application that helps to solve this problem. Unlike dd, partimage copies only used parts of the filesystem. To do this, it must obviously understand the filesystem it is copying, so it isn’t a simple raw copy like the one dd provides.

Partimage supports all popular Linux filesystems (ext2, ext3, reiserfs and so on) as well as Fat-formatted filesystems. It has limited support for NTFS. Partimage can also compress the data it backs up, which may help to reduce the size of the backup considerably, and on fast modern machines it makes little difference to the backup time.

Recent versions allow backing up over a network. Although it is a terminal text-based application, it is really no more difficult to use than a typical GUI program. If you’re using Ubuntu Dapper or Edgy, partimage can be installed from the Universe repository with

sudo apt-get install partimage

Reader Comments

   

Add your comment

Please keep comments constructive and free from abuse of any kind and swearing. If you wish to link to a product or service online, please do so in such a way that makes it clear that it is not spam. If you are connected to any such product you should make that clear.

We may use your comments in the magazine. We may edit your comments for clarity or to remove unacceptable material. We will attribute your comments but not share your email address.

We request your email address and record your Internet Address (IP address) in order to block spam from our site. We will never share this information without your permission.

All comments are reviewed by the Computeractive Team before being published. Please bear with the slight delay this causes, you don't need to post more than once.

Click here to read our Privacy Policy

Click here to read our site Terms & Conditions

Related articles

Build a game controller

Make a games controller for the Raspberry Pi

How to make your own controller for Raspberry Pi games – from scratch

Use the old-style desktop in Ubuntu

Use the old desktop in Ubuntu

People who prefer the operating system's old-style Gnome desktop can get it back with three commands

Resize images illustration

Resize or convert multiple images to a different format automatically

Irfanview uses an automation feature called batch processing to change multiple images to a different size, format and name far faster than it would take manually

Content Recommendation

Question & Answer

Q.Why is Windows Backup skipping files?

> Read the answer

Q.Why do my scanned documents display gibberish?

> Read the answer

Q.How can I convert MTS files to edit in Windows Movie...

> Read the answer

Best deals on the web

img

Samsung NP350E7C-A04UK

£349.99- Buy it now

img

Toshiba Satellite C850D-11Q (PSCC2E-00R00JEN)

£279.97- Buy it now

img

ASUS Eee PC X101CH-BLK043S

£239.99- Buy it now

Updating your subscription status Loading

Most popular articles

No matching document

Poll

Do you have Windows 8?

Jargon Buster

Computing terms explained in plain English

GIF

Grahics Interchange Format. A type of image file often used on the web, but now largely superseded by...

Great shopping deals from Computeractive

Information currently unavailable