November 28, 2004

Migrating A Movable Type Weblog With A Little Help From MySQL

This post comes primarily out on necessity as I am scheduled to move two blogs in the near future. I'm hoping it will serve as a task list for me. The second objective is offer any help to those who may be taking on the same task.

Assumptions:


  • A fair amount of knowledge of MySQL and phpMyAdmin

  • A decent knowledge of SQL

  • A decent knowledge of FTP and web site administration

  • The ability to have access to both servers/web spaces at the same time

Extra Help:
I can't say that I will be able to respond to any questions immediately, but if you have any please use the comments section or email.

Getting Started:
First and far most, BACKUP EVERYTHING! Whether you are a coding ninja or not, a CYA copy of your data is always a good thing. For your external files (custom images, style-sheets, etc), I would use the backup utility your ISP offers. If they don't offer one and you have FTP access, FTP your entire structure to your computer.

Second step is to export your weblog entries to a flat file. Do this using the Export utility in your Movable Type instance. Templates can be redesigned, settings can be reconfigured, but your entries cannot be relived once lost. Plus, we will use this later.

You will need to get your blog_id(s). You can do this by visiting the Main Menu of your Movable Type instance, and hovering over the link with the name of your weblog. In the status bar of your browser, you should see something like http://www.yoursite.com/mt/mt.cgi?__mode=menu&blog_id=<a number>. The "<a number>" is what you need. Write this down or commit it to memory, so you won't lose it.

Getting Your Database:
To export your data refer to 6.4 of the phpmyadmin documentation. It is pretty straight forward.

Setting Up The New Environment:
If you have the access to your new environment, I would get everything not associated with Movable Type situated first.

After that, set up a brand new instance of Movable Type following the installation instructions.

Once MT is up and happy, create any new author(s) and/or blog(s) you feel are necessary(Note: If you are going to use the same information, you can just duplicate the settings from your old environment). This is where that exported file of your entries will be handy. Using the Import utility in your new Movable Type instance, import the entries into your freshly created corresponding weblog.

So what do you have now? You have a weblog in your new space with the default Movable Type templates. If you want to redesign the look and feel of your site, you can stop here, you have successfully migrated. Since the vast majority of you probably want your old templates back, let's move on.

Database Mojo:
This is where the blog_id from earlier is needed. There are a number of ways you can get the information from your old database:


  • If you have access to your old environment you can access it from there.

  • Or, if you don't have access to your old environment and your new environment allows multiple MySQL databases, you can upload your database to your new environment (phpmyadmin documentation section 6.5).

  • Finally, you can do this before you migrate and save your templates to text files.

I will walk you through updating the Main Index template. This will be reusable for the rest of your templates.

Using phpMyAdmin run this query:

SELECT template_text
FROM mt_template
WHERE template_blog_id = <your blog_id>
AND template_name = 'Main Index'

Change your view to "Full Texts". Highlight the entire template text with your mouse and copy it.

Login to your Movable Type instance. Go to the Templates section. Select your "Main Index" template. Delete everything in the "Template Body" text area and paste what you just copied. Save the change, rebuild your files.

Note: Depending on if you have relative or absolute URL's for images and the like, you may have to make a few tweaks in the newly pasted template to locate the desired file in the new environment.

Repeat the query for each template you want to move and the look and feel of your site will be present in your new space. You could do similiar queries for your banlists, placements, or notifications. Everything is run by blog_id. It's an important number to have.

I hope this helps. I haven't cleared any of this with the lovely people at Movable Type. Have fun, but please be careful snooping around your database. Hold on to your backups and happy migration!

Posted by kyle at November 28, 2004 08:38 PM
Comments
Post a comment









Remember personal info?




Please enter the numeric code you see: