geek, technology

How To: Backup your Mac to a Dreamhost Server (Part 2 of 2)

03.09.07 | 46 Comments

(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:

The Plan

  1. Signup for a Dreamhost Account
  2. Create a new user with SSH login
  3. Using shared keys, enable SSH access to the server without having to supply a password
  4. Run rsync from the terminal to create a back-up of your home folder on the server
  5. Create an AppleScript that runs rsync automatically
  6. 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?

  1. Launch iCal
  2. Create a new calendar called “Scripting Cal”
  3. Create a new event called “Dreamhost Backup”
  4. 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.
  5. Set the alarm to “run script”
  6. 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”
  7. Set it to run 1 minute before the event
  8. Set the event to repeat daily

ical event
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.

Conclusion

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!)

Popularity: 7% [?]

some posts that may be related

46 Comments

your comments

Add your comment below, or trackback from your own site.
Subscribe to these comments.

Comment Policy: It's my site, I'll do whatever the hell I like.

You can use the following html formatting:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


« How To: Backup your Mac to a Dreamhost Server (part 1 of 2)
» command line idiot
Copyright © 2007-2008 command line idiot. All rights reserved.