Saturday, December 27, 2008

Backing Up in Ubuntu

One of the most frequent questions on the forums is "How do I back up in Ubuntu?"

Before I started using Ubuntu, I thought the best method was just to copy and paste files using the file manager (that's one way, of course, but it has its limitations). I'm going to recommend a few popular methods. This list isn't comprehensive--it just gives you some places to start. You can always investigate further once you're more comfortable with Ubuntu.

Backing Up Personal Files
rsync is what I use for backing up personal files. I used to copy and paste files using the file manager, but that would involve taking about an hour to back up all my music and erase all the old copies. rsync gives me the ability to copy over only the files that have been modified or added since the last time I backed up. Now, backups take me only about fifteen seconds a week.

The most basic way to use rsync is like this (command goes into the terminal):

rsync -av /path/to/source/directory /path/to/target/directory
For example, let's say your username is alice and you wanted to back up your home directory to your external hard drive that mounts at /media/usbdrive, you would use the command
rsync -av /home/alice /media/usbdrive

If rsync doesn't seem sophisticated enough for you, you can type

man rsync
to find more options than just -av. You can also explore rdiff-backup, which allows you to store (and restore) different date-stamped versions of the same file without taking up too much extra space. And, if you hate the command-line, try installing grsync, which is the graphical frontend to rsync. Here are some screenshots of grsync in action.

Backing Up Whole Installations
Not that System Restore is foolproof in Windows, but it's still a nice feature... at least in theory. Right now, Ubuntu doesn't have anything like System Restore. So if you're going to do any kind of experimental stuff with Ubuntu (for example, installing Beryl or Compiz), it's best to back up your system first.

PartImage is a nice little program that creates an image of your entire partition. You'll need a live CD for this, and you can find more details here about how to use it.

tar is an archiving command, but it can also be used to archive your entire system into one little zipped up bundle. Someone on the Ubuntu Forums wrote a nice little HowTo on backing up and restoring your entire installation using tar.

ddrescue allows you to copy a partition byte for byte to another partition or to a .img file. It's mainly designed for recovery of a crashed drive, but you can also use it as a way to back up (a non-graphical PartImage of sorts). The trick is that the name of the package is ddrescue in the repositories, but the command to use it is dd_rescue. So if you wanted to copy /dev/hda1 to /dev/sda1, you would type in the terminal:

dd_rescue /dev/hda1 /dev/sda1
Keep in mind that /dev/hda1 cannot be in use or mounted. If that requires you using a live CD, then so be it. You can also, if you don't want to erase /dev/sda1 completely, ddrescue to an image file and then mount the image to get the files off it:
dd_rescue /dev/hda1 /dev/sda1/hda1backup.img
sudo mkdir /recovery sudo mount /dev/sda1/hda1backup.img /recovery

No comments:

Post a Comment