Thursday, July 30, 2009

Using a USB external hard disk for backup with linux/Unix

In this article, I show how I set up a recently purchased USB external hard disk drive as a backup drive for my Linux desktop PC. I'll delete the default FAT32 partition, create a new partition, make a reiserfs filesystem, and show how to use rsync to backup your important data.

1. Partition the disk

I prefer reiserfs (Reiser 3). I know I'll never need to backup a Windows machine since I don't do Windows, so putting up with the inadequacies of FAT32 is simply not required. You may wish to rethink which fileystem to go for, or perhaps a different partitioning strategy if you have a seperate Windows PC. I'm going to go for a single large Reiser 3 partition. To do this, I first need to use cfdisk to delete the old partition and create a new one. You will probably need root access or sudo for this, depending on how your system is configured.
# cfdisk /dev/sdb
a. A FAT32 partition. Let's get rid of it and then see what we have left. Select [ Delete ] from the menu.

b. Right, nothing left. Time to create a new partition. This will be a primary partition, and I'll only make one - this whole disk is for backups. Select [ New ], [Primary] to create a new primary partition. Accept the default size offered, which should be all the disk space available.
c. Now write the new partition table to disk.
d. Type yes and enter to continue
e. You should now be able to [ Quit ].
So to recap, I've created a single primary Linux partition, using all the available disk space on my USB drive.

2. Creating a new filesystem


1. Now to create our filesystem of choice. I'll be using reiserfs, you can choose ext3 or whichever you want.
# /sbin/mkreiserfs /dev/sdb1


3. Running the backup


The command I now use for backing up my department directory in /dept partition
# cd /media/usbdisk/
# mkdir department
# cd /root/
# rsync -vrlptg /dept/department /media/usbdisk/department
4. Running the restore

# rsync -vrlptg /media/usbdisk/department /dept/department

No comments:

Post a Comment