May 11, 2013

To anyone who knows me or has read the last few posts, this next sentence will probably be a shock: there is a Microsoft program that I love.  It’s called SyncToy.  It’s a very minimalist, very easy to use program to syncing folders between locations, and I used to use it as my backup program, where I would have it do unidirectional syncs from my files to my backup drive periodically.  It took me a while when I switched to Ubuntu to figure out how best to do regular backups.  Ubuntu has a few built-in utilities with good GUIs, but none of them were really set up to do what I wanted.

The main problem was that I wanted to do incremental backups of all my data — ALL my data, which between text documents, pictures, recordings I’m working on, and mp3s means ~2TB.  That’s the main reason I do incremental backups rather than ever trying to do a system image or full backup.  I’m not afraid of having to reinstall my OS since I’m not a business and down time doesn’t mean that much, but I’m extremely afraid of losing any data.  That’s why rsync works so well for me.  Rsync is a very minimal command-line program that syncs files between locations, and comes with a lot of options for how you run the sync; I highly recommend it.  Of course, backups mean very little if you don’t run them regularly.

Once I got rsync figured out I still had to learn how to get it to run automatically.  This is where cron comes in.  Cron is the task scheduling utility on Ubuntu and other *nix systems. In principle it’s similar to the task scheduler in Windows, but it’s configured very differently.  Like many if not most other Linux utilities, it’s meant to be run from the command line.  For most tasks you’ll probably want to run them as your regular user account, so you can access crontab, which stores user-specific scheduled tasks, by entering “crontab -e” in the terminal.

This will probably open crontab in nano (which I usually prefer to vi), depending on what your default CLI editor is.  The slightly tricky part of using cron is getting used to the syntax.  Instead of simply inputting a time, you have to input 5 numbers separated by spaces: the minute, hour, day of the month, and month you want the task to run, followed by a number to represent the day of the week.  After these numbers telling cron when to run the task, you enter the path for the actual command to be run.  If you have a backup script called “backup” in your home folder, the path would be /home/<username>/backup.  Asterisks are used in place of numbers if you want the task to run during every instance of that type, e.g., putting * in the “month” spot would run the task every month instead of a specific month.  I have my backup script run every night at 3am, so I have “0 03 * * *”: “0 03” tells it to run at 3:00, and the asterisks tell it to run every day (of week and month) in every month.