Friday, 2005-08-19

Gmail backups

You can back up your Wordpress blog to gmail: here’s a post that explains how.

I’ve been doing this since October last year, here are some gotchas related to that.

This is my setup.

  • Blosxom blog
  • shell account on the blog server
  • gmail address
  • bash shell scripting nous

I run the following script from cron:

#!/bin/sh

HOME=/home/gustaf
DIR=$HOME/backup
DATE=`date +"%Y-%m-%d"`
# set filename extension to something other than ".tar.gz"
FILE=blog-$DATE.bak
MUTT=/usr/bin/mutt
# save crontab 
crontab -l > $HOME/save/crontab
# create backup file
tar czf $DIR/$FILE --exclude public_html/files/big  \
blosxom-data blosxom-plugins public_html bin save
# mail the file
echo ""| mutt -a $DIR/$FILE -s "backup $DATE" <my email>+backup@gmail.com

# prune old files
find $DIR -type f -name "blog-????-??-??.*" -atime +30 -exec rm {} \;

This zips up my blog and plugins, the bin directory, all CSS and .htaccess files, the crontab and my blogroll, and all smaller pics in a tar file. This is then sent to gmail. mutt makes it easy to send attachments from the command line.

The process leaves a bunch of files in the backup directory. All files older than 30 days are pruned.

As of today, the backup file is 1.3M 6.6M. According to the comments to the post referenced above, the gmail limit is 10M. You can add a check if your file gets bigger.

Make sure you can check the mail to the account you’re sending from, if the mail to gmail bounces you want to know about it.

Update 2007-09-11: I renamed the file extension as Gmail has started blocking files with the tar.gz extension. I also added a call to find to prune old files.

Friday, 2004-11-26

Migrating from Movable Type to Blosxom

This is how I moved my blog from MT to Blosxom. The process is very specific for my case — you mileage will definitely vary.

Pre-requisites

I had the following pre-requisites:

  • A good knowledge of Perl
  • A shell account at the target machine
  • A test machine running a free version of Un*x (OpenBSD).

I installed Blosxom on my test system and played around with CSS and flavours until I was happy with the look of the site.

Exporting from MT

Searching Google led me to this post. It concerned moving from MT to Drupal, but mentioned an important thing: the default MT export format is hard to parse. The method used instead was to export to XML, and parse that.

I downloaded the XML export template and the Perl file used to parse it, and modified them for my needs. They are available below:

The changes to the XML template are fairly minor. I added a new Index Template in MT and called it “Export XML”. The output file was set to “export.xml”.

The convert.pl script was modified in the following ways:

  • I changed the output from printing SQL insert statements to writing to files. The timestamps were modified to reflect the original posting date in MT.

  • I constructed new Blosxom filenames from the entry titles.

  • I mapped my MT categories to new ones via a hash.

After I had debugged these changes, I ran the script on an export downloaded from MT.

Importing to Blosxom

After I had this running, it was a simple matter of taring the files and moving them to the target server. After changing the relevant paths, I was up and running.

A friendly sysadmin installed a redirect at my old blog which pointed to the new one. The original MT archive posts were left alone to cater to old bookmarks, but I’m working on redirecting those too.

Update, 2004-11-02: The links to the files above were b0rked, but David McBride put me right about that. Thanks, David!

Update, 2004-11-26: Here is another article about moving from MT to Blosxom