Backing Up Your Web Server with Time Machine

Server backups: One of those behind-the-scene jobs that seem to be only an encumbrance with no glory, meaning that it gets pushed on the back burner until that date when a hacker invades your server and erases all your work. By then it's too late though, and you've a hoard of clients on your back demanding that you get their website back up ASAP.

Several months ago, I was experimenting with an AppleScript that would automate some of my publishing workflow. I wasn't careful enough though, because when I ran it, the first thing it did was try to replace EVERYTHING on my server with the folder to be published. Fortunately I had copies of most of the stuff on my hard drive, but it was a nerve-wracking 5+ hours until I had everything working again.

Creating backups of a server using the traditional method (logging into the admin panel, and going though a bunch of dialogs) is never very easy or convenient, and overall leaves much to be desired. You end up with a ton of archives, with no easy way to navigate/restore.

I began to look for an automatic, fast, and easy method to create backups.

The Solution:

I thought about what the ideal backup setup would be, and then it struck me: Time Machine! For those of you who aren't using a Mac, Time Machine is an awesome application that comes bundled with the OS which makes backing up your hard drive easy and automatic. You can launch the application and enter a space-inspired interface where you can view all the history of a certain file/folder on your mac, then restore it from any point in history that you wish.

The only issue is that files have to be on your physical hard drive for it to back them up. You could just use a FTP application to sync your server to a folder on your drive once a day, but remember, I wanted it to work automatically, with means scheduling. AppleScript+Automator+Calendar to the rescue!

How To:

I used YummyFTP ($10 on the Mac App Store, worth every cent) for this, as it seemed the perfect match for what I wanted it to do. Although it has a sorta' ugly interface, it's rock solid and packed with an advanced feature set, including good Applescript Support. Here's what the script looks like:
tell application "Yummy FTP"
    set bookmark to "bookmark name"
    connect bookmark
    using connection bookmark list remote folder "/"
    using connection bookmark list local folder "/Users/Username/folder/path/"
    with timeout of 32766 seconds
         using connection bookmark synchronize "Update Mac"
    end timeout
    disconnect bookmark
end tell
What this does is:
  1. Launch the application "Yummy FTP".
  2. Activate it.
  3. Connect to "bookmark name" (which you will need to change to reference the name of your FTP bookmark).
  4. Chose the "/" (top) folder on the server side.
  5. Chose the local folder that you have referenced (wherever you want the backup to be stored).
  6. Synchronize the two folders by updating the local folder ("Mac") to exactly mirror the server.
  7. Disconnect from the bookmark, and dismiss the application.
Now, all we need to do is schedule the script to run automatically. The easiest way to do this is through Automator, another application that comes bundled with OSX:
  1. Launch Automator, and Choose "Calendar Alarm" from the dialog.
  2. From the actions library (left sidebar), find the "Run Applescript" action, and drag it into the workflow canvas.
  3. Paste the aforementioned script into the text area, making sure that you have changed "Bookmark name" and "path/to/local/folder".
  4. Save the workflow. Another dialog should come up, asking you to name the calendar alarm. Give it a meaningful title, such as "Server Backup Script". Hit the save button!
  5. Calendar.app will launch. Chose to edit the event "Server Backup Script". Set it to repeat daily at some crazy time in the middle of the night (Mine's set to 2:30 am).
And you're done! You now will have a copy of all the files on your server on your Mac, updated daily, with no more work on your part. Time Machine will do it's stuff, and you will have a super-sweet and uber-awesome way to browse and restore the files on your server.

Notes: Get an extra external hard drive and keep it off site in case of robbery/fire/flood/whatever. Once a week, wipe it clean and do a complete Time Machine backup to it.

The only two FTP applications I have are Yummy and Forklift. Of those two, Yummy is the only one that is Applescript-able. The script will only work with Yummy. If you get a script to work in any other FTP application (Transmit?), please let me know in the comments and I'll add it to the article!

No comments:

Post a Comment

I'm Caleb Grove

Yep, that's me. I'm a 17 year old web unicorn and own OnRamp Web Design. My skill base is quite broad, though my real focus lies in UX and UI design for the web. When it comes to designs, I'm a perfectionist, scooting 1 pixel at a time.

My main blog captures all my web-related thoughts that exceed 140 characters. Anson S is my personal blog, where I pander in politics and religion. You can tweet me on Twitter at @SirCalebGrove, circle me on , or friend me on Facebook.

About this site

This is my playground. CalebGrove.com harnesses the power of HTML5 and CSS3. It was built using my web design weapon of choice, Freeway Pro, using a inline flexible system. Responsiveness was hand-coded. The blogs are hosted by Blogger, whose template code was generated by the Blogger actions. Website hosted by GJX Hosting. Creativity provided a disturbed mind, and not much else.

No unicorns where harmed in the making of this website, except through caffeine overdose.