MT+MySQL·PHP 05a: Exporting and importing weblog posts
Transfering one’s posts and comments intact is probably the most critical task in moving your weblog from one host to another. Fortunately, Movable Type has an efficient import/export mechanism, as the Importing Entries section of the MT documentation explains:
In addition to exporting your data from another weblog CMS, you can export your entries from Movable Type itself. This allows you to keep local backups of your weblog content for safekeeping, as well as to transfer data between blogs, by combining the export and import mechanisms.
NOTE: be careful when exporting data from Internet Explorer; all versions of Internet Explorer have a bug where data marked as plain text can be intrepreted as HTML. The symptom of this bug is that all of your exported data will run together onto one line. If this is the case, use Netscape when exporting data.
I didn’t even bother with Internet Explorer. Apart from the glitches I’ll explain below—none of which were browser-related—importing and exporting via Mozilla worked smoothly.
Due to limitations with my current hosting service, I’m still running MT version 2.11 with the Berkeley database. I’ve installed MT version 2.21 with MySQL at my new host though I intend to upgrade to version 2.5 quite soon. The transfer process I’m about to describe depends on running the new weblog with a MySQL backend.
Exporting from the old weblog and importing into the new one works just as the documentation suggests, with one proviso, which is a variation on the perennial GIGO (Garbage In, Garbage Out) rule. In this case, it’s GOGI (Garbage Out, Garbage In).
Unless you are incredibly lucky, you’ll almost certainly have to run the import a number of times. A MySQL backend makes this quite straightforward. After each unsuccessful import, all you have to do is delete the MySQL database tables and reconfigure Movable Type to create a fresh MySQL database, ready for the next import attempt.
Paramount in this procedure is the fact that, if you wish to preserve your permalinks, the entry IDs in your new weblog must match those in your old weblog. If you’ve deleted posts from your old weblog and you want to avoid implementing a complicated set of redirects, you’ll need to add dummy posts to replace those you deleted. (You can filter out these dummy posts with Brad Choate’s SQL plug-in.)
Let’s assume that you’ve exported your posts from the old weblog then run the import, only to find that the import stalls or you end up with a mismatch between the number of posts in the old weblog and the number of posts in the new weblog. Both glitches happened to me. Firstly, the import stalled after only three posts had been imported. Secondly, I wound up with twice as many posts and comments in the new weblog compared to those I’d exported from the old weblog. I finally managed a successful import on my seventh attempt—but without MySQL, I would have been stuffed.
The stalled import occurred with the following error message:
Invalid convert breaks value ''
When I checked the export file, I found that the fourth post contained the lines:
CONVERT BREAKS:
PRIMARY CATEGORY:
whereas in posts one to three and five the corresponding lines were:
CONVERT BREAKS: 0
PRIMARY CATEGORY:
I used a regular expression find and replace in TextPad to replace:
CONVERT BREAKS: \nPRIMARY
with
CONVERT BREAKS: 0\nPRIMARY
At that point, with a weblog containing only three posts, I had to delete the tables from the MySQL database, reset MT, and start again. You’ll have to follow these steps after each unsuccessful import attempt:
- Use phpMyAdmin to drop all the tables from your MySQL database.
- Run mt-check.cgi to ensure that your MT installation is sound.
- Upload mt-load.cgi to your mt directory.
- Change the permissions on the mt-load.cgi file to 755.
- Run mt-load.cgi (this creates a fresh MT installation).
- Delete mt-load.cgi (failure to delete this file results in a serious security flaw in your MT installation).
- Log in to the fresh weblog with username
Melodyand passwordNelson. - Edit your profile, changing the username and password and adding your email address & birthplace (in case you forget your password).
- Log out then log in again to confirm your username and password.
- Modify your import file, based on the errors you encountered during the import process.
- Import again.
The import then proceeded smoothly, sort of. I’d exported 698 Entries (i.e. weblog posts) and 1297 Comments from my MT 2.11 + Berkeley DB weblog. When I imported these entries and comments into the MT 2.21/MySQL weblog, I wound up with 1408 Entries and 2594 Comments.
What went wrong? A bunch of different things. I’ll explain them in detail in the next installment.

Just for future reference, you could also have used $ in your regex to mean "end of line."
Yours worked, which is the main thing.
Posted by: Dorothea Salo on 1 November 2002 at 12:13 AM