How to Make Unix Backup Scripts with rsync
Rsync is a good way to create and maintain a “mirror” of specific folders on your unix system. It’s not good for archiving, for cloning disks, or running a “full/incremental” backup system.
What rsync does is compare two folders, and syncrhonize them.
The following command will backup my home folder to an external disk called “/media/extdisk”.
rsync -a /home/johnk/ /media/extdisk
Of course, life cannot be that simple. I have some huge folders with a lot of chaff that I don’t need. First, I don’t want to backup my Downloads directory. Nor do I want to backup my Freenet storage, which is 10 gigs.
I also have a 24 gigabyte Music folder, but don’t want to scan that every singe time I run a backup. Conversely, I want the Desktop folder backed up frequently.
The typical unix way to handle this situation is to write a backup script. Here’s my script. It’s stored in the target backup directory, so it’s not listed. I “cd” into the directory and run the script:
#! /bin/bash rsync -av /home/johnk/Pictures/ Pictures rsync -av /home/johnk/Sites/ Sites rsync -av /home/johnk/Desktop/ Desktop rsync -av /home/johnk/Documents/ Documents
The backup takes around two minutes to scan 24 gigabytes of data and back up the few new files that appear.