Sunday, November 6, 2011

Migration from Drupal to Blogger

(update2: added link to Drupal 7 version by Nico Schlömer)
(update: Migrated the code to GitHub and implemented minor improvements.)


It has finally happened: this blog is migrated away from Drupal to Blogger. My reason to move towards Blogger (and thus not away from Drupal) is very simple: No need to patch/update the application.
An important thing for me is that I wanted to keep all my blogposts, timestamps and comments. Unfortunately it looks like most people move away from Blogger towards Drupal and the web is full of code and information to export your data from Blogger in XML and then import it into Drupal.
But information how to upload everything into Blogger was nihil.
So I wrote a php script to do the export while keeping:
  • posts
  • comments
  • tags / categories 
  • publishing date
However there are a few quircks.
  • It seems to work only for Drupal 6, not 7.
  • Comments are (partially) anonymized because of a security feature of Blogger
  • URLs are not customizable, so you will create dead links
  • Images are not changed or imported. So manual work is still necessary
To use this script first create your blog into Blogger, create a test posts and export it to XML. Then run my php script and copy paste the output towards the bottom of the XML, where your test post is located.
Save the file and import it again in Blogger. It usually takes some time, but in the end you get the message that everything is imported correctly.

The code to do this is located here: https://github.com/cvandeplas/inet_scripts/blob/master/drupal_to_blogger.php .
A version for Drupal 7 has been written by Nico Schlömer is located here: https://github.com/nschloe/drupal2blogger

18 comments:

  1. Your code was a GODSEND! Thank you sir, two quick notes

    First: if you don't use the db_prefix setting (my drupal install was a very old first installed, then upgraded many times site - so mine has always been $db_prefix = '';) then you need to alter the code above just removing drupal_ from all the SQL statements above.

    Second: and this is completely a NOOB mistake by me, but it might save others some pain - after it runs, remember to "view source" to actually get the right code you need put in your import xml file - I went nuts trying to figure out what was wrong with code and why PHP PRINT was "stripping out" the HTML - only to have a facepalm moment when I realized it was the damn browser :(

    Third: don't forget to change the Author section in the middle away from Christopher, you can find your info in the export he instructs you to create earlier.

    Christophe Vandeplas
    http://www.blogger.com/profile/01574685218200894861
    christophe@vandeplas.com


    Sadly wish there was an easier way to get pictures over too, but what your code did already saved me hours of work getting my site moved! +1 for the post!

    ReplyDelete
  2. This was wonderful!
    A lot of the posts were added like five times, but easy to delete in Blogger…
    Thanks a lot!

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Used your code. Worked well. Thanks.

    One small change I made: added the comment author name (but not email, of course) at the end of the comment text in brackets, so a reader can at least have some indication who the now anonymous comment was from.

    $body [posted by: $author]

    ReplyDelete
  5. I have done the migration successfully today, and your code worked very well, so thanks a lot for sharing!

    Also a thank you to David, your tips for sure saved me from much pain :-)

    ReplyDelete
  6. Anne: Thanks for the feedback.

    I also integrated some feedback from David and uploaded everything to my github account.

    To make everything easier I've set the Content Type to text/xml and to a downloadable file. So instead of having to show the source you simply get a file called drupal_to_blogger_export.xml

    ReplyDelete
  7. Another satisfied user. Thank you Christophe.
    Needed to change localhost under "...should probably NOT change..."

    ReplyDelete
  8. hey, thanks for the work, this really is the only 1 search leading from google to "migration from drupal to blogger" :D

    is there a way to specify only one user id and the damn blog node type? (I have a multi-blog with more users posting and a forum, and 1 wants to transfer to Blogger)

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. I think you should make clearer that this is only for Drupal 6.

    ReplyDelete
  11. Alright so, I took drupal_to_blogger and modified it for Drupal 7; get it at https://github.com/nschloe/drupal2blogger. It also supports nested comments!

    ReplyDelete
  12. Great ! I updated the post and the github page to add a more clear link to your version.

    ReplyDelete
  13. I followed the readme, the error bX-7rv9ue appears when import to blogspot.
    I used the drupal2blogger

    ReplyDelete
    Replies
    1. For problems with drupal2blogger you should contact Nico on his page : https://github.com/nschloe/drupal2blogger/issues

      Delete
  14. Ok I am trying this on an old and very long lived Drupal site on shared hosting. I am running the php via ssh and getting "Cputime limit exceeded: 24", any way to limit the cputime for the script and re-run from where it stops, or maybe spawn of separate instances for each export?

    ReplyDelete
    Replies
    1. Ok got that sorted, found that it had a lot of spam comments so I removed the comments export section and it finishes in less than a minute. Now I can't figure out where I am supposed to paste the export from Drupal into the blogger export, I tried just removing my test entry from the to tags and that didn't work.
      I have also tried removing from the first through to the last in the export to no avail, all come back with no posts imported.

      Delete
    2. ok so on a whim I just tried importing the direct export from Drupal and it seems to be working, just importing posts 5 times, ah well easy to delete.

      Delete