Back up blog or FTP directory with AppleScript

Apr 25, '12 07:30:00AM

Contributed by: lucaslivingston

All those many different WordPress plugins to back up my blog looked too daunting to me, so I decided to create my own simple Mac-native solution using AppleScript. This AppleScript does the following:

  1. Simulates a double-click on the alias to my web server (where my WordPress blog lives) to mount it as a WebDAV volume (just like iDisk)
  2. Runs the handy Unix backup command rsync to copy the remote contents locally
  3. Unmounts my web server

I then set up a daily iCal event to run the script at 4 a.m. Since I already have CrashPlan backing up my hard drive, that takes care of archiving periodic versions of the backup, just in case.

Here's the script:

set filepath to "Macintosh HD:Users:USERNAME:Library:Favorites:www.example.com"
tell application "Finder" to open filepath
delay 30

do shell script "rsync -av /Volumes/www.example.com/blog/ '/Volumes/Backup/wordpress-backup'"

tell application "Finder" to eject "www.example.com"
Set you own user name, domain and backup destination in the script.

[kirkmc adds: While this is a simple solution, I think it's good to remind people how easy it is to back up a server with rsync. While the submission mentions WordPress blogs, this can be used for any server directory. It's worth reading an older hint about using rsync for backups and a much older (from 2003) detailed walkthrough of creating backups using rsync.

It's also worth pointing out that while there are many WordPress backup plug-ins available, it is also a good idea to use one. The backup in this hint only backs up files, not the actual WordPress database. I use the WP-DBManager plug-in for automatic backups of my database, that are sent to me by e-mail.]

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20120423212741164