super simple wordpress backup
I use an app called gtimelog to track the time I spend on projects. It’s a very simple app which doesn’t get in the way. I’ve been pretty happy about it for the last 6 months or so. A couple of days ago it started corrupting it’s datafile and I didn’t have a recent backup. Putting only a couple of days worth of data was pretty painful so I decided to give dropbox a try.
All the software does is synchronize ~/Dropbox with your online storage. You get about 2Gb for free which is more than sufficient for what I need.
Lesson learned, I won’t run into this problem again. I have cron spawning a script every hour or so which compares the file with the previous version and drops a fresh copy in ~/Dropbox if it changed.
Then I started thinking, what about backing up wordpress sites this way. I don’t exactly care for the SQL dumps. Installing wordpress from scratch is easy and fast enough. I do care about the content, more specifically about the WXR dumps but I don’t have any desire to go in there every day and do a manual dump. Getting to those dumps from the outside turns out to be pretty easy. Just put a file with something like this in the toplevel directory of your blog:
<?php
include 'wp-config.php';
include ABSPATH . '/wp-admin/includes/export.php';
export_wp();
Done! Simple isn’t it? The XML is streamed to standard out which means you can call this with a webbrowser.
Make sure you give the file a hard to guess name. Kind of sucks to see an exact copy of your content show up somewhere else, doesn’t it? I used a random string, pulled that through md5sum and tacked .php onto that. Try guessing that
Then, to actually execute it automatically add this to your crontab
wget -O - http://example.com/hardtoguessfilename.php \
| gzip - > ~/Dropbox/dump.gz
The dump will be automatically synchronized within seconds and you have something less to worry about.










