I use a lot of tools when I migrate sites, and one of them that I’ve used a few times before is a WordPress importer that takes your Drupal database and migrates it into a WordPress format. It’s available here, and I’ve mentioned it a few times before – does a great job, although only a partial job (it doesn’t import images into the database and attach them, but there are other tools to do that part of it, including some I’ve written).
So this particular tool, unbeknownst to me, actually nukes your entire WordPress database before it imports the Drupal content. I’ve only ever used it on new sites before, so I didn’t think anything of it – I set it up as usual, connected it to both databases, ran the import script and …
I found out that everything was gone. This is a site we’ve been working on for about 12 months on and off, waiting on designers, content, videos, new logos, etc – it has been a long time coming. Anyways, no big deal, I just went looking for my backup – and couldn’t find it.
It’s the best. I wanted to both throw up and lie down and cry at the same time.
Turns out I was just looking in the wrong folder, and had it restored in another 5 minutes, but it brings me to my next point – if you’re going to import data into an active site, do a swing migration. It’s simple, can be done in a few steps, and is no big deal.
Set up a new database, then import the contents of the existing WordPress database. In this case, I just called it temp, and gave the Drupal user access to it in preparation for the migration.
Perform the migration using the temp database instead of the live one.
Switch the wp-config login details over to the temporary database. Make sure you save the original database login details first, comment them out or copy them to another file. The temp database should have most of the original WordPress database, so login details will be the same, everything will work, just no content will be available. Once you’re logged in, go to Tools, Export, and pick your content type and date range. For this usage case, I picked everything in the past 12 months, which was after the original database import was performed. It will save it as an XML file which you can use to import.
Change the wp-config login details back to the original database login details, log in, and again go to Tools, but this time go to import. Click on WordPress at the bottom, install the import plugin, and run it.
Choose the XML file you just saved, import it, and let it run its course. You may have to change some settings if the authors don’t match, and you may run across some post duplication, but it will import everything you need.
Clean up the import – Drupal has some annoying quirks to it with the default settings, like using nodes and permalinks only containing numbers. Some of the tools I use to clean this up include generating post slugs to match the title, then migrating the images from these same posts (both plugins that I have written as tools to migrate Drupal to WordPress). Really, some of these steps need to be done on the temporary database before you transfer the posts to the live database, but at least you get the general picture. You’re all set at this point to continue working on your live site.