Tiny Code

Tiny Code

Sunday, February 10, 2008

Backing up data

I've been struggling trying to find a decent solution for backing up my wife's laptop computer. The program I'd been using ended up not backing up some key files. We almost ended up losing all her photos when the hard disk in her laptop started dying recently. It's never a good sign when you hear clicking noises when you try to list a directory. Fortunately the use of SpinRite and a little luck allowed the drive to continue functioning long enough to manually copy the files to an external drive.

After trying a number of different backup programs and not being fully satisfied with any of them, I decided to use something simple. The tar program has been around since the early days of Unix. Tar stands for Tape ARchiver and it was originally used to archive a group of files to a tape device. The beauty of tar is there are versions available for almost any operating system you can think of. That makes it easy to examine the tar files on any system to verify I've backed up all the files which needed backing up. I'd long ago installed cygwin (a version of the most common Unix utilities for Windows) on her laptop so I was good to go. Cygwin can't fix all of Windows' shortcomings but it is able to make Windows much more useful. The Windows command line tools are so woefully underpowered that I no longer consider using them for anything.

Having decided to use tar, there were still a couple other problems which needed to be solved. The resulting tar file for even a partial backup is likely to be quite big. By default tar concatenates all the files with some file information (file name, size, permissions, etc) about each file added. So using gzip to compress the tar files is highly recommended to avoid using too much space on the backup device.

The gzipped tar file for the backup of just the data files on her laptop ends up having a size of just over 11 GB. The external USB hard drive and NAS (network attached storage) drive we have are both formatted as FAT32 to make it easy to use on Windows, Mac, and Linux systems. That presents a problem since FAT32 drives have a maximum file size of 4 GB. So I was forced to use the Unix split program to split the huge tar file into smaller files which can be copied to a FAT32 drive.

After building the tar file, I was able to dump a list of all the files contained in the tar file. I was also to use the find command (the cygwin/GNU version not the lame Dos/Windows version) to build a list of all the files on her hard disk. Then it was a simple matter to use grep to get a list of all the JPG, GIF, DOC, etc files in both the listing of all files and the listing of all files in the tar file. That made it easy to verify that I've managed to back up all the data files.

Whew! It was a lot of work but now I can finally rest easier knowing all her data files are safely backed up.

No comments: