A PHP Developer's Blog - Joakim Nygård

About jokke.dk

jokke.dk is the personal website of , a software architect, entrepeneur and Mac user living in Copenhagen, Denmark. Read more »

Search the Site

Backup Your Mac to a Remote Location

9th April, 2007

With harddrives continuing to fall in price, having access to hundreds of gigabytes at home is increasingly common. This calls for and provides the means for easy backup of the thousands of files, we create every year with photos being the largest group.

Having your backup sitting next to the computer is less than optimal. In case of fire or theft, the backup will likely be destroyed or stolen too. You'd think that the hosting companies would offer increased storage as the price per gigabyte drops but with the notable exception of Dreamhost, this is not the case. Offering 170GB and practically unlimited traffic for about $8 a month, Dreamhost fits perfectly as a remote backup storage solution.

Michael Lee has written a two-part guide to backing up your Mac to Dreamhost. Even if his steps are beyond point-and-click, they are well explained and anyone with interest should be able to follow them.

Building on his AppleScript to automate the backup procedure, I've added Growl support and sending a mail upon completion. Growl is a great little application that lets other applications post unobtrusive notifications of events (CD ripping complete, new email, current iTunes track, etc.) on the screen.

First, we check if Growl is running at all

tell application "System Events"
    set isRunning to ¬
        (count of (every process whose name is "GrowlHelperApp")) > 0
end tell

If it is, we register the script as a notifier and post a notification that the backup has started

if isRunning then
    tell application "GrowlHelperApp" ¬
        register as application "Dreamhost Backup Script" ¬
        all notifications {"Backup"} ¬
        default notifications {"Backup"} ¬
        notify with name "Backup" title "Dreamhost Backup" ¬
        description "Starting backup to Dreamhost..." ¬
        application name "Dreamhost Backup Script"
    end tell
end if

Then comes the actual backup code. We store the result of the backup in backupResult

set backupResult to do shell script "rsync -avz --delete-after ¬
~/Documents/ USER@SERVER:~/laptop.bak/Documents/"

Finally, we send an email with the results of the backup:

tell application "Mail"
    set newMsg to (make new outgoing message with properties ¬
        {visible:false, content:theContents, ¬
        subject:"Dreamhost Backup on " ¬
        & short date string of (current date)})
    tell newMsg
        make new to recipient with properties ¬
        {address:"your@email.here"}
    end tell
    send newMsg
end tell

This provides feedback when the backup starts in case you're sitting in front of the computer and sends a mail with a log of what was backed up and if any errors occured.

« Optimizing PHP Through Habits  –  Speed up MySQL on development boxes »