April 28, 2008
I currently support four public facing sites that use Wordpress as the back-end content management system (CMS). I also have a Wordpress test platform on my laptop, where I tinker with several different themes, that supports another four sites. So, I’ve got eight different Wordpress installations to update each time a new release is made available. Running through the update steps is tedious at best and, with the need to not inadvertently overlay the theme or plugin directory in each installation, there is a fair amount of stress. Using ftp to accomplish the update isn’t difficult, but after doing the same steps four or five or six times, it is easier to make a mistake.
Wordpress does provide instructions for how to accomplish site updates using Subversion. Unfortunately, my host provider doesn’t have Subversion installed, nor are they inclined to add it just for me. As I am comfortable with command line tools, I decided to investigate rsync as a solution for my update tasks.
Rsync is remote synchronization software that allows you to keep files in two locations in sync with each other. This is not a rsync tutorial, so I high encourage you to read the man page, or visit one of the numerous sites explaining this powerful tools uses.
For my purpose I want my Wordpress update steps to be the following:
Where [options] are the command options, source_directory is the location of the files you want to synchronize, and target_directory is the location of the files to be synchronized.
There are a myriad of options for rsync, but the three (or four) that I used are:
Running the command with the -n switch is a good idea, if for nothing else to verify your source and target directories. (Once you run the command to your satisfaction using -n, simply edit the command from your shell history, and remove the “n” leaving the rest of the command untouched.)
Here then, is the command as I run it to update my remotely hosted sites:
Obviously, you will need to substitute your username and server name. After responding to a password prompt, the command executes and your Wordpress installation is updated from top to bottom, leaving any theme or plugins behind. Any modifications you’ve made to Wordpress code will be overlaid, so you’ll have to re-apply those once rsync is finished.
To update my locally hosted test sites, which are built upon MAMP, the command looks like this:
The final step would be to encapsulate the rsync commands in a shell script so they can be executed without the need to retype them each time they are needed. Or you could create an alias in your bash profile for each destination and execute the sync that way.