Posts Tagged 'Wordpress'

Systematically backing up a wordpress blog

I’ve been meaning to write about this forever, but now someone else has done all the work already! The script presented there works wonderfully. I’ve just made a tiny addition, because I don’t like ending up with a directory full of huge XML files. Those of you who have been here before will have probably guessed already: the addition is to check the backup in to a revision control system.

To begin with, this is what my patch to the script looks like:

--- wordpress_backup.perl	2008-11-12 22:24:57 +0000
+++ wordpress_backup.perl	2008-11-12 23:05:32 +0000
@@ -13,14 +13,13 @@
 my $path_to_file="/path/to/file/";
 my $url="https://$username.wordpress.com/";
 my $author="all";
-#Filename format: fileprefix.date.xml
+#Filename format: fileprefix.xml
 my $fileprefix="wordpress";
 ###############################################  

 #Change that if you want
 my $agent="unixwayoflife/1.0";  

-my $date=((localtime)[5] +1900)."-".((localtime)[4] +1)."-".(localtime)[3];
 my $mech = WWW::Mechanize->new( agent => $agent );
 $mech->get( $url."wp-login.php" );  

@@ -38,7 +37,7 @@

 ##Download the file
 $mech->get($url."wp-admin/export.php?author=$author&submit=Download+Export+File&download=true");
-$file_name="$fileprefix.$date.xml";
+$file_name="$fileprefix.xml";
 $mech->save_content( $path_to_file.$file_name );
 print ("Download ttt[OK]n");  

@@ -50,4 +49,5 @@
 print ("Login out ttt[OK]n");  

 print("File successfully saved in $path_to_file$file_namen");
+system("bzr commit -m "* wordpress_backup.perl was here"");
 exit 0;

As you can see, only four lines changed – the maximum I could manage, since I haven’t ever edited a perl script before :P

All you then need to do is putting in your blog’s details at the top, and run it. The last thing will fail – the “bzr commit”, but running it once will get you the initial XML file to check in to revision control (if you happen to be a native English speaker, can you tell me if that should be “check-in to” or “check into”, or yet something else?). Having the file, say “wordpress.xml”, and assuming you have bazaar, you can now bring the backups under version control with a simple

bzr init #this will create a .bzr tree under your current working directory
bzr add wordpress.xml
bzr commit -m "some happy message about the first commit"

The next time you run the perl script it will overwrite wordpress.xml and commit changes to the repository. If you have a big weblog, this could save you quite some disk space…

Moving…

Ok, I moved this weblog to WordPress.com (it was on Blogger before). I wouldn’t even have been looking for something else if it wasn’t for Blogger lacking any decent form of backup options. The “advanced use” section of the help pages has a slightly bizarre option that involves changing your template settings. And then there is a Windows-only tool. I’m sure this will change sometime soon, since Blogger is owned by Google and I believe they support DataPortability.org, but it wasn’t soon enough for me – having backup plans in the future doesn’t protect your data (as I also just wrote on my new personal blog)…

WordPress not only allows you to create backups (using an export operation), but also to import your Blogger weblog (how convenient!). I can go on to sum up a lot of other nice features, but in short: I created an account, played around for a bit in the powerful Dashboard interface, and was sold.

Another charming feature is its GPL licensing, which makes your blog even more portable – not only can you take your posts and comments, you can simply set all of them up on a server of your own. In fact, a wordpress package is available in the Etch repository, as I found while I was exploring and comparing alternatives for weblog services. I also found that it almost didn’t make it into Etch – the discussion linked to has a well-balanced discussion about security issues, should you be interested in that sort of thing.

Now that I’ve moved, I’ll set up a complete backup mechanism (doing the xml export is of course only a first, be it essential, step) and will post about that here soon.