WordPress Backup Redux

WordPress Backup Redux

I currently work with WordPress (WP – hey whatever happened to WordPerfect?) and am not overly happy with the backup offerings that are out there – at least the ones available on the freemium model. So I’ve had to ‘roll my own’ and thought I’d share with the group.

The architecture of WP is fairly straightforward. It’s a content management system (CMS) that has come a long way in recent years. You create pages and posts, and most of the content typically resides in a MySQL database, which has also seen great improvements in recent times. (But for the life of my why can’t they implement constraints!). The first step then is getting the data out of the db and shifting it to another place. This will be our ‘off site’ backup, if you will.

Here’s some breadcrumbs to the solution I’ve implemented:

1) Perform a data dump using the MySQL tool mysqldump. This can be scripted out and scheduled via a cron job.

2) Identify core WP files that you would need in the event of a restore. I’d suggest placing them into two categories:

a) Files that don’t change too often. These would include themes, plugins (of which you should maintain a definitive list for reference purposes.) and custom pages and templates.

b) Core files that you are likely to update on a semi-regular basis such as functions.php, .htaccess, wp-config.php, etc

For the first category a manual backup should suffice. How you perform this will depend on your hosting provider (hosts that don’t support remote shell access present new and interesting challenges).

Better to script out the second category so that you have some type of ‘set-and-forget’ solution. I’m using a PERL script for this purpose, to add the files to a gzipped tar which I can then copy elsewhere.

3) Copy the files to Google drive – that calls for another script. I came across this gem and made a few very slight tweaks for my own use. It’s slow, at about 50K per second, but solid. A few tricky bits – you will need the Google Auth info that applies to your own account and in particular the refresh token. Check out this post for that info.

There you have it – WP backup ‘lite’ for the code savvy.

PS: The Google Drive documentation can be difficult to navigate due to the different API versions – v2 and v3. Sorry kid, you’re on you’re own there.