Upgraded from Berkeley DB to sqlite

Welcome to sqlite. It's easy to upgrade (well, sidegrade, technically) your Movable Type installation from Berkeley DB to sqlite. Besides sqlite being cooler these days, I definitely like the idea of having the whole thing in one file with a single, more portable format. Also I haven't heard as many complaints about sqlite's reliability as I have Berkeley's; hopefully that's not only because Berkeley's had more eyes on it.

These are the instructions to follow, though they don't state a few things clearly enough for my taste:

  • You'll need to download the "Upgrade Version" of Movable Type to get the mt-db2sql.cgi script.
  • Do not comment out your DataSource directive, or mt-db2sql won't know where your Berkeley database. This is tricky since the upgrade script will tell you it worked instead of warning you it didn't find any data to load in the new database.
  • The Database is the path to your sqlite file, as it says in the complete installation instructions.
  • If you use the suggested sqlite path of db/mtdb, and you don't use a cgi-bin, you probably want to use .htaccess or something to prevent folks from fetching your database over the web.

You won't fully believe it works until you remove the Berkeley DB and see MT has all your data still. Here's the Python CGI I used to pack up and delete the Berkeley DB since I don't have a shell account. (Actually I ran this as two programs, one doing the ZipFile stuff and f.write(fname) and one with only the loop doing os.unlink(fname).) I tried to use tarfile at first, but found it's new in Python 2.3 and Cornerhost understandably doesn't run 2.3 yet.

#!/usr/bin/python import cgitb; cgitb.enable() import os os.chdir('/home/markpasc/mt-db') import zipfile f = zipfile.ZipFile('berkeley.zip') for fname in os.listdir('.'): f.write(fname) f.close() for fname in os.listdir('.'): os.unlink(fname) print """Content-type: text/plain OK!"""