Search Tillamook Rage
Google Custom Search

9.19.2007

Backing up your Linux system

Backing up your files is one of the most important things any computer user can do. Why risk losing years of hard work? I have backups of everything I've done back to my "Windows 3.1 on a 486" days (1988 for the record, yeah I feel like an old man). Now backing up can be done in 3 ways; to a CD or DVD, to a fileserver, or to another hard drive. I'll explain the latter two here as most people, I'll assume, can burn a CD or DVD backup. In the next few days I will add the directions for automatically backing up.

I did this using Xubuntu 7.04 (Feisty) as the OS and a Xubuntu 7.04 Live CD for the portion using a live CD. I also like to use SimplePup (http://www.puppylinux.org/user/viewpage.php?page_id=1) for a small live boot, but I wanted the consistency here. I'll warn you again when the time comes, but messing up any commands in this can be a death knoll for all the data on your hard drive. Double, or even triple, check all your command line inputs and make sure you change what's written here to what your particular case is. I don't want to be held accountable for sloppy typing in the terminal, so please be careful.

Method 1: File Server Backup

The first way to back up is to a file server, a Samba server in this case. If you don't know what one is, you most likely don't have one and so you should either burn a CD or DVD backup or go to Method 2, setting up a Samba server is a discussion for another day. If you have a different type of file server than Samba, sorry but I don't have directions for that yet.

First, make sure you have enough hard drive space on the server for the amount of data you want to store on it. If not, you'll need to add another hard drive or get less data. I suggest the first option. Now, boot to your live CD, in this case Xubuntu 7.04. Once in the XFCE environment (AKA: the desktop) you'll need to install pyNeighborhood by going to Applications > System > Add/Remove... and searching for pyNeighborhood with the All Available Applications selection in the drop down menu in the upper right hand. Once completed you will have all the tools needed for dealing with Samba which are, quite unfortunately, not included with Ubuntu and its derivatives.

Now, open a terminal window and type sudo mkdir /mnt/samba to create a directory to which you can link directly to the Samba server. Now mount your samba directory you want to save to into this /mnt/samba directory, for example sudo smbmount //192.168.1.100/home/user/backup /mnt/samba at which point you will most likely be asked for the password to the Samba server. To break this down into English that says "As root (sudo) mount the Samba file system (smbmount) on the server (//192.168.1.100) in the backup directory (/home/user/backup) to be given the local folder samba so I don't have to type as much (/mnt/samba)." Now you can use the dd command.

The dd command is extremely powerful and can act as a way to destroy data or make backups similar to Norton Ghost. BE EXTREMELY CAREFUL WHEN USING DD, A TYPO CAN ERASE YOUR DRIVE!!!!! With that said, let's play with dd. It stands for "data definition", but some people lovingly call it "destroys data." For our backup we will define 2 options of dd, if and of. if stands for input file and of stands for output file. In this example we want to back up our entire drive to the server in an .img file, similar to an .iso image in principle. To do this type sudo dd if=/dev/hda of=/mnt/samba/mybackup.img. At this point make sure /dev/hda is the drive you want to back up, and change this to whatever drive you want to back up, and that mybackup.img is whatever name you want to give your image. Now check again, making sure that everything is typed correctly with spaces in all the right places. Hit ENTER and let it sit and do its thing. Backing up my 60GB drive takes 20ish minutes, so sit back and relax. There shouldn't be any visible signs if it's working correctly. If it finishes without error you'll get back to the prompt (#) and you're home free. To restore this backup do the same procedure, switching the if and of values. It's a beautiful thing, isn't it?

Method 2: Backing up to another drive or partition

Using this procedure you can backup an entire drive or partition to another drive or partition. First, make sure you have enough hard drive space on the destination drive or partition (the one you're copying to) for the amount of data you want to store on it. If not, you'll need to use a different hard drive. Now, boot to your live CD, in this case Xubuntu 7.04. This method is much easier than the previous in term of length of steps, but again BE EXTREMELY CAREFUL WHEN USING DD, A TYPO CAN ERASE YOUR DRIVE!!!!!

With that said, let's play with dd. It stands for "data definition", but some people lovingly call it "destroys data." For our backup we will define 2 options of dd, if and of. if stands for input file and of stands for output file. In this example we want to back up our drive or partition to another drive or partition. In the terminal type sudo dd if=/dev/hda of=/dev/hdb to copy one drive to another. To copy one partition to another it would be the same except with partition numbers, such as sudo dd if=/dev/hda1 of=/dev/hdb1 or if you want to do a backup on the same drive, a poor choice for safety reasons, it would be sudo dd if=/dev/hda1 of=/dev/hda2. At this point make sure /dev/hda is the drive you want to back up, and change this to whatever drive you want to back up, and that /dev/hdb is the drive you want to back up to. Now check again, making sure that everything is typed correctly with spaces in all the right places. Remember: whatever drive or partition is after of= will be completely overwritten. Hit ENTER and let it sit and do its thing. There shouldn't be any visible signs if it's working correctly. If it finishes without error you'll get back to the prompt (#) and you're home free. To restore this backup do the same procedure, switching the if and of values.

Sometimes you'll need to reinstall the Grub boot loader when restoring from an image. If this happens you'll be told by Grub during startup when it fails to load your OS. Just insert the Live CD and use the restore option. In Xubuntu, at least, there's an option labeled Reinstall Grub boot loader. Run this and you'll be fine. Otherwise from the terminal type grub-install /dev/hda or whatever your hard drive is.

Now you have all the different ways to back up. There are others to back up single files, but that's a simple copy and paste from one drive to another. To copy and paste single files to a Samba server follow the initial backup directions for making the link in /mnt/samba and then just copy and paste into that folder.

Happy backing up!

For the record Norton is a registered trademark of Symantec Corporation, please don't sue me if I didn't credit this properly.

No comments: