PetesProjects:   Backing Up Your Linux System

PetesProjects Home Backing Up with Bash >>>

Does the world really need another backup utility? No, right?

Well, I need one, one that does exactly what I want done, the way I want it done. After all, this is why I use Linux in the first place: when things go bad, it will be my fault, not that of some Redmond, WA programmer.

I do a full backup once a month, and an incremental backup once a week, or whenever I think it might be necessary. Modifying the kernel, for example, is a really good opportunity for backing up. (No, I've never modified any kernel source code. But if I do, I'll be sure to back up first...)

My strategy is to do full backups as infrequently as possible. A gzipp'd tarball of a full backup is around 70 megabytes and slowly growing. An incremental backup can be as little as a few thousand bytes to as many as several megabytes, depending on how much time has passed since the last full backup. When you do an incremental backup, you back up everything that has been modified or added since the last full backup. As the weeks go by, each incremental backup will be larger than the previous. Once you do another full backup, you can delete all the old incremental backups, since they've been incorporated into the full backup.

If you want to see what drives people away from Linux and back to Bill Gates, check out how the tar utility does incremental backups! Clear as crystal, right?

I use two scripts and two data files for backing up. They're all described in the following pages. The first script is a bash script. This one actually creates the backup file, by using a list of directories and files to back up.

The second is a Perl script, which locates all the files that have been modified or created since the last full backup, and creates a list creates a list of files to incrementally back up.

The following pages will describe these scripts, how they work, and how to use them.

A third script is also described: a Python script which is actually a translation of the Perl incremental backup script. This script should not be taken as a demonstration of how to use Python -- while it's an intrepreted object-oriented language like Perl, it's far more powerful than Perl. The script -- you'll find others like this in other projects when they're posted -- is simply my way to learn the language, and understand how it differs from Perl. And it does do many things differently. The Python page is basically a description of the differences found while trying to do some simple file-related and system-related tasks.

Limitations:

This backup strategy is limited to backing up parts of the home directory, not the kernel or any files outside the home directory that are routinely updated during operations. After all, my goal is to keep my checkbook intact. If the OS goes south, I can stick in the floppy to get back up, and then fix whatever I messed up. But the checkbook, budget, diary, agenda and whatever else I have, will be kept current to the last incremental backup.

Here are some ideas for improvement:

  • Modify the tar command in the bash script to not strip any leading "/";
  • allow directories outside of home directory to be included;
  • allow files and directories to be excluded (e.g. ~1.5G of mp3 files in one directory).
PetesProjects Home Backing Up with Bash >>>