Cook Computing

Importing/Exporting Movable Type

May 24, 2003 Written by Charles Cook

When I moved this website to a new hosting service one of the problems was that the Perl module for Berkeley DB was not available on the new server. MySQL was available, so I had to export the contents of the blog to a text file and import them into a newly created blog on the new server.

This works fine except that if you have ever deleted any entries from the blog, the numbering of entries in the destination blog will be different. The MT export routine simply writes out the entries sequentially, ignoring entry id's, and the import routine creates a new set of entries sequentially starting from 1. Some extra work is required to retain the numbering of your entries and so maintain the validity of the entry permalinks.

The first step is to change the export process so that the entry id is output with each entry. In the mt/App/ file, modify the export subroutine to add a line writing the ID, for example:

AUTHOR: <$MTEntryAuthor$>
ID: <$MTEntryID$>
TITLE: <$MTEntryTitle$>
STATUS: <$MTEntryStatus$>
ALLOW COMMENTS: <$MTEntryFlag flag="allow_comments"$>
CONVERT BREAKS: <$MTEntryFlag flag="convert_breaks"$>
ALLOW PINGS: <$MTEntryFlag flag="allow_pings"$>

Export the entries from the blog to a text file, say mt.txt. The exported entries now need to be sorted by entry id with dummy entries being inserted to fill the gaps (the id's must start from 1). At this point I removed the lines beginning ID: but this may not be necessary. Import the entries into the empty blog and then delete the dummy entries. Finally verify that the process has been successful and the entry id's in the new blog are the same.

One other problem I encountered was unless the MySQL database is new you will find that the imported entries will not be numbered from 1. A quick way of completely re-intializing the MT tables from the database is to add the following to mysql.dump. Then run mt-load.cgi to re-load MT from scratch.

drop table if exists mt_author;

drop table if exists mt_blog;

drop table if exists mt_category;

drop table if exists mt_comment;

drop table if exists mt_entry;

drop table if exists mt_ipbanlist;

drop table if exists mt_log;

drop table if exists mt_notification;

drop table if exists mt_permission;

drop table if exists mt_placement;

drop table if exists mt_plugindata;

drop table if exists mt_template;

drop table if exists mt_templatemap;

drop table if exists mt_trackback;

drop table if exists mt_tbping;

Note that this may need to be changd for any version of MT other than 2.63. I guess a similar approach could be used for PostgreSQL or SQLite.