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.

Automating everything

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.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • E-mail this story to a friend!
  • LinkedIn
  • TwitThis

3 Responses to “super simple wordpress backup”

  1. I agree this is an easy solution for a techie but for those who are not technical in nature (read: fear opening a web browser), what about using the wp_backup plugin?

  2. I looked at a couple of those plugins. They all seem to focus on the database and/or the files and I care for neither of those. I prefer to import posts into a fresh reinstall, rather than restoring a database dump.

    More importantly, I needed something I can automate locally. I really don’t want to get database dumps in my e-mail :)

    Thanks for the suggestion though

  3. Nice idea. As a Dropbox user for some time now, this might come in handy.


Leave a Reply