(continued from part 1)
In the first part of this tutorial, we fired up a dreamhost account and got our home folder synced up with it. Let’s check where we are in the master plan:
Signup for a Dreamhost Account Create a new user with SSH login Using shared keys, enable SSH access to the server without having to supply a password Run rsync from the terminal to create a back-up of your home folder on the server
- Create an AppleScript that runs rsync automatically
- Use iCal to run the AppleScript backup daily, without doing a thing!
In this second part of the tutorial, I’ll show you how to create an AppleScript that does the backup for you automatically, and then we’ll set iCal to run that script automatically. Ready? No? Well, it’s a blog, so you can leave it and then come back later when you are. No duh.
5. Create an AppleScript that runs rsync automatically
One of the very cool things that Mac OS X has included is a programming language called AppleScript. It lets you write computer programs in a very clean and simple environment – the AppleScript programming language resembles the English language, which makes it easy to use.
We’re going to write a simple computer program. It only has one command, which is my favorite kind of computer program. Inside your Applications folder, and you’ll find a folder called “AppleScript”. Inside is an application called Script Editor. Launch it, and copy the following text into the blank window without any line breaks (again, don’t worry if it breaks the lines for you, just don’t hit enter yourself between the lines):
do shell script "rsync -avz --delete-after ~/Documents/ USER@SERVER:~/laptop.bak/Documents/"
Remember to replace USER and SERVER with your own info. Click the hammer icon labeled “Compile”, and if you entered everything correctly, it should change the colors of the text to blue and black. This script should look very familiar; it’s just like the command we entered in the terminal the first time we synced everything up. The only thing that’s been added is the term “delete-after”. This tells the rscync program to delete anything on the remote server that no longer exists on your local computer. This will keep you from accumulating a bunch of trash in your remote server.
Save the script someplace where you will remember it. Name it “dreamhost backup.scpt”. If you want to go poking around, there’s a folder already named “Scripts” inside the Library folder (/Library/Scripts), which would be a fine place to save the script. It’s not important where you put it, as long as you can remember where it is.
6. Use iCal to run the AppleScript backup daily, without doing a thing!
The last hurdle we need to eliminate is the human factor – a backup plan that requires you to constantly remember to backup your data is bound to fail. Instead, let’s make the automatic computrix machine remember for us!
Apple’s iCal software has a very cool little feature that we can use to automate our backups. iCal allows you to set alarms to remind when an event is coming up in a few minutes. Instead of the alarm making a sound, we can set the alarm to run an AppleScript. You see where this is heading?
- Launch iCal
- Create a new calendar called “Scripting Cal”
- Create a new event called “Dreamhost Backup”
- You can set the time to whenever you like. I have mine set for 11 PM, since I’ve usually finished working on my projects by then, but my computer is still awake and online.
- Set the alarm to “run script”
- A new line will appear, asking you to point to the script you want to use (you may have to select “other” first). Navigate to “dreamhost backup.scpt” and click “select”
- Set it to run 1 minute before the event
- Set the event to repeat daily
There are a few caveats here. In order for this to work, your computer needs to be awake, connected to the internet, and iCal has to be running. Otherwise, the backup won’t happen. If you want to run the backup in the middle of the night, you’ll have to go into your system preferences to adjust when the computer wakes up.
So, in conclusion, that’s why I think Zombie Nixon will run, and win, in 2008. Oh wait, that’s a different post. If you have any questions, please feel free to leave a comment. If you’re a level 23 Unix Mage, and would like to correct or amend anything in this tutorial, please, feel free!
(think this tutorial is useful? take a second to Digg it!)