Automated data backup with cron and rsync

Though I've known of cron and rsync for many years, I never took the time--and it doesn't take much time--to put the two together to solve my data backup problems. After reading jwz's post I decided to go ahead and set my laptop up to sync my important files to the Seagate FreeAgent drive.

I have a few folders in my home directory that I really care about. These include my photos, my music, my code, and my books.

To sync the files in those folders with my external drive, I typed the following into a text document in gVim:

5 22 * * * rsync -vaxE --ignore-errors /home/steven/music/ /media/freeagent/steven/music/ 09 22 * * * rsync -vaxE --ignore-errors /home/steven/photos/ /media/freeagent/steven/photos/ 08 22 * * * rsync -vaxE --ignore-errors /home/steven/books/ /media/freeagent/steven/books/ 06 22 * * * rsync -vaxE --ignore-errors /home/steven/dev/ /media/freeagent/steven/dev/

It'd be much cleaner to just have a main sync/ directory within my home directory that contained all the directories I wanted to backup, but I've got 4 separate lines that sync each directory in turn (at slightly different times--the first runs at 10:05PM (5 22), the others follow a few minutes later)

After typing those lines into a file, I saved it as cronjobs. The name isn't important.

To load the lines into my crontab (the file cron actually uses) I typed crontab cronjobs

To check that your crontab is loaded, type crontab -l to list the current contents of your crontab.

By the way, the format of a crontab file is as follows: {min} {hr} {day} {month} {day of week} {command} An asterisk is a wildcard, meaning all valid values apply. To run a command every hour on the hour of every day of every week of every month, you'd have a line like the following in your crontab: 0 * * * * /usr/bin/mycommand

As for the parameters in the rsync command itself, the vaxE switches specify that the command run (v) verbosely, in (a) archive move, use one (x) filesystem, and (E) preserve executability of files. The --ignore-errors tells rsync to delete from the destination folders even if there are errors. As I write this, I can't really see any reason to run verbosely or with the --ignore-errors flags as I'm not telling rsync to delete extraneous files (my destination directories can contain extra files that aren't on my laptop; they don't need to be perfect mirrors). I play fast and loose with my backups, using hastily adapted commands, apparently.

This system has been working flawlessly the past few days. If for some reason the drive isn't mounted I miss a backup, but my files don't change that often. I could solve this by running another cron job that mounts the external FreeAgent drive before the backup period.