Jul 23, 2009 1
Automating WordPress Backups using Automator and Transmit
After publishing Bits of Tech with WordPress for a couple of months, I was looking for an easier way to backup my WordPress installation. From the beginning, I was running a backup every weekend using Transmit to download the whole directory housing my WordPress install, then compressing the downloaded directory, renaming it with the date and moving it to my backups folder.
Knowing that there had to be a better way, I looked at using AppleScript and Automator, eventually settling on Automator. While my process may differ slightly from yours due to differences in hosting providers, it should be very similar to how I do it. Today, I’m going to share my process step-by-step in hopes that someone else can benefit from it, and even improve upon my process.
As I mentioned earlier, I use Transmit 3 by Panic Software. The first thing I did was create a Favorite for my SFTP site. My hosting provider, DreamHost, gives you a home directory, and in that directory you can create a new directory for every domain you host, so the default path in my favorite is set to my home directory. Here’s a picture of my favorite, with my username obscured.

First, we need to create some folders for the backups. In my user profile folder, under the Sites folder, I have created a folder called Backups. Inside Backups, I’ve also created a folder called Temp. That’s where our download will be stored temporarily before we compress it. Inside this folder, create a folder with the same name as the directory on your FTP server that houses your WordPress install. In my case, it’s bitsoftech.net. This is just a temporary folder that we’ll use later to create an action (without having to download the whole directory first).
Now that I have the favorite defined and the folders created, we can move along to creating our Automator script. Open up Automator from the Applications folder, and when you’re presented with the “Choose a starting point to open a new workflow” window, choose Custom and click Choose. You should now have a new, blank workflow.
The first step is to set up an action to download our directory containing our WordPress installation. In the left sidebar, choose the Internet category under Library. If you have Transmit installed, you should see the Transmit icon with Download Files next to it in the pane just to the right of the Library. Drag that into the large right pane of the Automator window, and you have your first action in the workflow.
Now we need to configure the Download Files action. Where it says Connect To choose Favorite. Next, choose the name of the favorite you created for Favorite. In my case, it’s DreamHost Root. For Resume Mode, choose Replace. Now we choose our destination for the downloaded files. Click Destination, then choose Other…, and you’ll be allowed to browse to your folder. Choose the Temp folder under your Backups folder. Lastly, we have to choose our Remote File Path. Click the + symbol below the Remote File Path box, and type the path to your files. Since my favorite points to my home directory, I will enter the directory that holds the WordPress installation, bitsoftech.net/. Make sure you put the trailing slash in path or Transmit will only download the folder and not it’s contents. See the example below.

Our next step is to create an archive of our downloaded files. Under the Library in the left pane of the Automator window, click Files and Folders, then locate Create Archive and drag that into the right pane of the window just below our Download Files action. You’ll notice that there’s now a triangle protruding from the bottom of the Download Files action connecting it to Create Archive. This means that the output of Download Files—the directory we downloaded—are the input that Create Archive will use.
In the box labeled Save As, we will give the archive a name. I am using Bitsoftech-(date)-(time).zip. The (date) and (time) are variables that Automator will populate itself. To create the name, type the name you want to use, such as Bitsoftech-, then click the Variables button above Library in the left pane of the Automator window. Choose Date & Time, and drag Today’s date to the Save As box in the Create Archive action on the right. Click the little white triangle inside the Today’s Date bubble you dragged over and choose Edit. From the Format drop down menu that appears, choose Custom Format. Now drag the Month, Day of Month, and Year bubbles into the box above them. Next, click the little triangle inside the Month and Day of Month bubbles and change the format to “01″ and “05″, as shown below, then click Done.

Now, back in the Save As box in the Create Archive action, type another hyphen, then go back over to the Variables under Library and drag Current time over into the Save As box. Click the little triangle in the Current Time bubble, choose Edit, then Custom Format from the drop down menu. Drag the Hour and Minute to the box above them. Inside the hour bubble, click the triangle and choose “01-24″ so our hours are displayed in military time. Leave the Minute bubble as it is, then click Done. After the Current Time bubble in Save as, type .zip. From the drop down menu next to Where, choose Other… and navigate to your Backups folder or wherever you want to store the archive. Check off Ignore Unreadable Items, and your action should look similar to the image below.

Now that our download and archive actions are complete, it’s time to do some cleanup. Choose Actions from just above Library in the left pane again, select Files and Folders, and drag Get Specified Finder Items over to the right pane of the window just below Create Archive. Now, from the Action menu at the top of the screen, choose Ignore Input. You’ll notice that the triangle connecting Create Archive and Get Specified Finder Items disappears and the two are no longer linked. This is very important, otherwise Get Specified Finder Items will take the items you specify and the archive you just created and move them to the trash in our next step.
Click the Add button at the bottom of the Get Specified Finder Items action, then navigate to your Temp folder, select the directory inside it and hit Add. Your action should now look like the image below.

Now, we’re going to move that folder to the trash. Back in the left pane under Library, then Files and Folders, drag Move Finder Items to Trash just below your Get Selected Finder Items action. You’ll notice that Get Selected Finder Items and Move Finder Items to Trash are linked. This means that the items you selected in the Get Selected Finder Items will be moved to the trash. This cleans out your Temp folder for the next time you run the workflow.
The last action in the workflow is to quit Transmission. Under Library in the left pane, click Utilities, then drag Quit Application to the right pane below Move Finder Items to Trash. From the drop down menu, choose Transmit. If it doesn’t show up, choose Other… then navigate to your Transmit application. Uncheck Ask to save changes, and your workflow is complete.
Now, we have to save our workflow. From the File menu at the top of the screen, choose Save As…, then change the File Format to Application. Give it a name at the top of the window—I used “Bits of Tech Backup”—navigate to where you want to save it, then click Save.
Now you have a simple one-step process to back up your WordPress installation. You can manually run this backup by double clicking the icon, or you can schedule a cron job to run it automatically.

