I’m currently in the process of setting up a MediaWiki farm.  As I stated in my previous post on creating a MediaWiki farm, I have a number of already existing MediaWikis that I need to move into my MediaWiki farm. This post outlines the steps I followed in order to move those existing MediaWikis, into my new farm.

First a Bit of Research

A number of people have posted that its just simply moving the LocalSettings.php file and image directory into the new directory, changing some words in the LocalSettings.php file and voila…it all works.  But this wasn’t the case for me.  I’m not sure if its because of the symlinks or what, but I was running into problems when I did this.

So I did a comparison between a moved wiki and a wiki created within the farm.  Interestingly enough the ones created in the farm were indicating that their $wgScriptPath was /wikis/[wiki-name].  Now when I set up my MediaWiki, I didn’t put it at the web root, instead I put it in a containing directory called wikis (clever huh).  One reason I did this was because I had other things on the server beside MediaWiki (WordPressMU for one) and I didn’t want there to be any conflicts.

Another reason I did this was so that I could set up a DNS to point to the wikis directory.  So if you go to http://wikis.wheatoncollege.edu/domingo you’ll see a wiki that’s part of the farm but its not sitting at the root of a server called wikis.wheatoncollege.edu, its sitting at fred.wheatoncollege.edu/wikis.  So…

  • wikis.wheatoncollege.edu = fred.wheatoncollege.edu/wikis
  • wikis.wheatoncollege.edu/domingo = fred.wheatoncollege.edu/wikis/domingo

I digress…

So I couldn’t figure out why this change was happening (I’m sure it has something to do with symbolic links) and I honestly didn’t have time to try to figure it out, and besides the web interface install script nicely creates a LocalSettings.php file for you anyway, and no one did a lot (if any) customization for the wikis at my institution.  So why not just use the web based script?

Backing Up a MediaWiki Database

So at this point all I’m doing is really moving over the database.  I could (if I wanted to) not even move the database, I could just connect the current MediaWikis’ databases to the new interface.  You can do this by entering in all the information that you used before into the web based install script.  But I don’t like the names my databases were given :) (ok that’s not the real reason…the real reason is so that i can keep the old ones running for a day without it affecting the new one)

So I did a MySQL backup:

mysqldump -u [mysqlrootuser] -p[mysqlrootpassword] --add-drop-table -B > [mysqldumpfile].sql

Note that I’m using the --add-drop-table mysql option.  What does this do? Well when I restore the database, it will look in the existing database and see if the tables already exist.  If they do, it’ll drop them and then re-add them.  If they don’t, it’ll just add them.  This means that essentially its wiping EVERYTHING in your database and replacing it with everything in your backup.  So if there is a table not in your backup that you want to keep…re-run your backup.  Or restore the tables one at a time (this is an option with MySQL).

Now I stated that I wanted to change my database’s names.  If I simply restored the database using:

mysql -u [mysqlrootuser] -p[mysqlrootpassword] < [mysqldumpfile].sql

It would restore with the same name as before.  Now I thought if I ran this command:

mysql -u [mysqlrootuser] -p[mysqlrootpassword] [newdbname] < [mysqldumpfile].sql

It would restore with a different database name, I was wrong.  I’m sure there is a way to do it from the commandline, but I’m in a hurry.  So I opened up the .sql file with TextWrangler (a Mac text editor) and found the database name (it occurs four times in the top part of the file) and changed it (much thanks to Carol Ou for confirming I could do this).  If you do choose to go this route, make sure you have a backup of the .sql file before you edit it.

A couple of quick notes about doing a backup this way:

  1. before you restore the database, you’ll need to create the new database (with your new database name).  you can do that with a quick create database [newname]; query.
  2. once you restore the database, there will be no MySQL users associated with the database, but there will be MediaWiki users associated with the database.  A MediaWiki user does not equal a MySQL user.  One is so that you can go into the GUI and edit the wiki and the other is so that MediaWiki can write information to the database.  When you run the MediaWiki web install script, it will allow you to create MySQL users for the database.
  3. after you restore the database do a quick show tables; query in MySQL to make sure the data was really restored.  doublechecking is always important.

Backing up the Images

The last piece that you’ll want to remember to do is create a backup of the images.  This is simple enough to do, just tar and zip it all up:

tar -cvzpf [backupname].tgz [wikidirectory]/images

At this point you’ll have all of the images in a tarball ready to move into your new wiki’s image directory.

Now On To Moving a MediaWiki into Your Farm

Now that I have a backup of the database and a tarball of the images, I’m ready to move the MediaWiki over.  One thing to note, all my MediaWikis are the same version (yay).  If you have different MediaWiki versions, you’ll probably want to update them before doing the following steps.

  1. Create the directory the MediaWiki will live in under that wikis directory you set up (see above).
  2. Restore the MySQL database as its new name.  You can do this by:

    mysql -u [mysqlrootuser] -p[mysqlrootpassword] [newdbname] < [mysqldumpfile].sql

    Another thing to check is whether or not table prefixes were used when the MediaWiki was originally installed. In my case, one of the MediaWikis did have prefixes; I checked this by running a simple show tables; query in MySQL.

  3. Create the symbolic links for the MediaWiki.  You can use my other post on creating a MediaWiki farm if you’re not sure how to do this.  I’ve also created a script that walks the liaisons here at Wheaton through creating the wiki.  Its works…but I could improve it and hopefully I’ll update the file when I do.
  4. Move the untar the images directory that you tarred up before.  You’ll want to untar it in the MediaWiki’s directory.  Doing this will move all the images over to the new wiki.
  5. Once you create the symbolic links, you’ll want to go to the web install script and run it.  This includes:
    • database name [the new one]
    • database username [you can create a new database user]
    • database password [again you can create a new one]
    • database prefix [only if you entered one for the previous incarnation of the wiki]
    • wiki admin and password [best to use the previous one...if you have it]
  6. Finish up the install by moving the LocalSettings.php file into the MediaWiki’s main directory, changing permission on the file, and deleting the config directory.
  7. If the LocalSettings.php file was altered for any of the MediaWikis (in my case one was).  Go in and remake those changes.

And voila! MediaWiki moved.