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:
What this does is:
tell application "Yummy FTP" set bookmark to "bookmark name" activate 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
- Launch the application
- Activate it.
- Connect to
"bookmark name"(which you will need to change to reference the name of your FTP bookmark).
- Chose the
"/"(top) folder on the server side.
- Chose the local folder that you have referenced (wherever you want the backup to be stored).
- Synchronize the two folders by updating the local folder (
"Mac") to exactly mirror the server.
- Disconnect from the bookmark, and dismiss the application.
- Launch Automator, and Choose "Calendar Alarm" from the dialog.
- From the actions library (left sidebar), find the "Run Applescript" action, and drag it into the workflow canvas.
- Paste the aforementioned script into the text area, making sure that you have changed
- 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!
- 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).
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!