Category Archives: geek

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

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

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

Time: Two 30 minute session, with a break between.
Geek Level: Played Dungeons and Dragons, but didn’t own your own dice.
Written for: Mac OSX 10.4.8 (should work on OS 10.2 and up), Dreamhost server account

Ever since my complete meltdown at the beginning of the year, I’ve been like a backup zealot. All of my computers are now on a regular back-up rotation with SuperDuper, and I’ve built an automated off-site backup plan too. This post will walk you through how to build an off-site backup of your data.

Some background

With so many companies offering website hosting, providers have started to compete on both price and storage space. Dreamhost has a plan that offers 170 GB of server space for $8 a month. For just a second, don’t think about that as a website server, think of it as a hard drive that you can rent for $8 a month, only this hard drive is maintained by somebody else, and they keep a backup copy of everything on it, so that if it crashes, your data gets completely restored. As a bonus, this extra hard drive you’re renting from Dreamhost keeps growing in size by 1 gig every week. Even if you’re not planning on building a website, that kind of cheap storage space is well worth the money.

There are two huge advantages to off-site backup on a server. First, if something catastrophic happens, like a fire or theft, I need to have my critical files stored in some other location. Secondly, this enables me to access those critical files from any computer, anywhere. I don’t need to worry about bringing my lecture notes to class with me – I can access them on the server when I get there.

So, I’ve decided to use the extra storage space on my Dreamhost account to keep regular backups of all my critical data. I keep a copy of my Documents folder on my Mac synced to the server, as well as a full copy of my audio hard drive, and all of my samples. Today, I’ll show you how to setup the same backup system I use, and how to automate it so that it backs up your data even if you forget.

(Note: Dreamhost doesn’t allow you to keep pirated media on their servers. If you have a ton of BitTorrent movies and TV shows on your computer, and you sync them up to the server, you’ll get a friendly little email from Dreamhost asking you to take them down)

This tutorial has a pretty high geek rating – it requires you to use some programs you might not be familiar with, like Terminal, and the Applescript Editor. It’s written to be understood by casual computer users, so here’s the deal – I’ll gladly offer personalized tech support to anyone who opens a new Dreamhost account using this link: Dreamhost Signup. I get a little kick-back from them if you do, which in turn makes me a happy little tech-support guy. If you sign up for a new account, I’ll work with you to get this working right.

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!

Before we begin, please do a local backup of your computer to an external drive, using SuperDuper or some other applications. We’re not doing anything here that will break your computer if you follow the directions, but it’s always a good idea to backup before you do anything new to your system.

1. Signup for a Dreamhost Account

Ready? Click here. Pick whichever plan works for you – the basic plan is probably enough for most people. Sweet! You’re already 1/6th of the way done!

2. Create a new user with SSH login

When you created your new Dreamhost account, you created a default admin user. The first thing we’re going to do is add another new user that will only be used for backups. Think of users as separate drawers in a filing cabinet. Your account can have a bunch of users, each with their own drawer. Each drawer has its own separate login and password. This way, your backup data stays separate from any data you’re using for a website.

Dreamhost will send you an email with details about your new account. There are a few things you need to write down and keep handy. First, it will tell you which server your account is on. It will be something like admiralty.dreamhost.com. Whenever this tutorial uses the word SERVER, replace it with the info from that email.

add userNext, the email will give you details on how to access the control panel for your hosting plan. Login, and look for the “Users” tab on the left sidebar menu. Then, click “add a new user”.

When the new page loads, under “Type of User Account” select shell. This will allow you to login directly to your server and pass files back and forth.

ssh account

Write down your user name and password. Again, whenever this tutorial uses the words USER or PASSWORD, replace them with the user name and password you’ve just created.

It’ll take 10 minutes or so for Dreamhost to get the new user up and running, so now would be a good time to brew some coffee and put on The Dailies CD.

3. Using shared keys, enable SSH access to the server without having to supply a password

Ok, ready? It’s about to get very geeky. Don’t be scared. Most of you think of computer applications as graphic windows that you click in and drag things around in (think iTunes). Those aren’t really the applications – they just control the applications. The applications are running under the hood. In the next few steps, we’re going to use some applications that don’t have graphic interfaces – you operate them by typing commands, which the application then carries out. That’s the only difference. Don’t let it scare you. If it makes you feel more comfortable, just copy and paste the text that’s here, and only change things like the SERVER, USER or PASSWORD.

Launch the “Terminal” application. It’s in your Applications folder, inside a folder called “Utilities”. Whoah! Check that out! Your geek rating just went up 4 points.

You’re going to enter some text commands into the terminal. You should see a string of text in the window, followed by a $ dollar sign (called a command prompt). Type the commands after that $. You can simply copy and paste what’s here, remembering to replace SERVER, USER and PASSWORD with your own info.

Let’s make sure the SSH login to your account is working. Type the following:

ssh USER@SERVER

You will get a warning saying that the authenticity of the host can’t be verified. Type “yes”. Next, you will be prompted for your password. Type it, and hit enter. Congratulations, you are now connected to your new server! Now type “exit” to close the connection.

In order for our automatic backup to work, we need to be able to connect to the server without having to enter in the password each time. Rather than retype the whole article, let me point you to the Dreamhost support wiki article. It’s pretty clear, just type in the commands as they appear. Replace example.com in their tutorial with your SERVER info, and you’ll be fine. To see if it worked correctly, exit out of your server, then type

ssh USER@SERVER

This time, it should connect you without asking for a password. Sweet!

4. Run rsync from the terminal to create a back-up of your home folder on the server

Ok, now we’re ready to do the first major backup of your data. We’re going to use an application called “rsync” to do that backup. Rsync doesn’t have a graphic interface, it runs from the terminal. It’s job is to compare two different files or folders, called a SOURCE and a DESTINATION, and to make changes to the destination. The advantage of rsync is that it only sends that data that needs to be changed, which makes our backup much quicker. Enter the following into the terminal, all on one line (don’t worry if it automatically makes line breaks for you, just don’t hit return until you’ve entered the whole thing)

rsync -avz ~/Documents/ USER@SERVER:~/laptop.bak/Documents/

Here’s what you told it to do:

  • “rsync” tells the terminal which program to use
  • “-avz” tells rsync which settings to use. This set of letters tells it to preserve some important information about the file permissions, and also tells it to compress the data so that it requires less bandwidth over your network connection.
  • “~/Documents/” gives rsync the SOURCE it should look at. In this case, it’s gathering data from the Documents folder in your user account. If you want to backup your entire account, replace this with just “~/”, and do the same to the following step.
  • Finally, “USER@SERVER:~/laptop.bak/Documents/” tells rsync where to put the files. USER@SERVER should look familiar – it’s the login to your dreamhost account. The last part of the command, “:~/laptop.bak/Documents/” creates a new folder on your server, called “laptop.bak”. Since I’m backing up many different computers, this helps me keep everything straight. It puts the data from your Documents folder into a similar folder on the server. If you changed the source folder to “~/” then change this to “USER@SERVER:/~/laptop.bak/”

This first time running the sync may take quite a while, depending on how much data you have, and how fast your network connection is. You may want to leave it running overnight. The good news is, once you’ve done this sync one time, it will only have to transfer the data that’s changed. It generally takes less than a minute for me to run the backup, unless I’ve altered a ton of data.

It’s perfectly fine to leave this project right where it is, and pick up the second half later. In fact, I’m going to save it for a second post. Rest content in the knowledge that your critical data has been backed up to a remote server. Next post, I’ll show to automate the backup, so that you can forget all about it. While you’re waiting, why not take a minute to digg this post.

(continue reading part 2)