My hard disk is dying! How do I make an emergency backup?

Disaster has struck and your hard disk is in its final death throes. No problem, you made a backup last night, right? Of course you did… but a pipe burst and you lost your backup tapes?

Assuming that you’re trying to backup a UNIX or Linux system:
(if it’s Windows or Mac… let’s let someone else fill this in later)

If your disk is in the process of dying, it’s probably in a fragile state. You want to avoid writing to it, and you want to make your backup right away and quickly. Let’s assume that you have shell access to another UNIX/Linux machine with enough disk space to copy the entire drive of your dying system. If you don’t, then go knock on some doors and come back when you find one.

Here’s the plan: Log in as root and use tar to make a backup of the entire filesystem. Instead of writing the output to the disk, we’re going to pipe that output across a SSH connection to your spare host. Here’s the command: (login as root first)

tar -zcpf - / | ssh username@spare_host "cd backups_dir; cat > backup.tar.gz"

Watch the output for messages about read errors. If your disk is dying there will probably be some files that cannot be read. If you’re lucky, this won’t include any important files. Also, tar isn’t exactly the best way to backup the filesystem (due to open files and such)… but you’re in a hurry and it should get most of your important files.