TurnKey Linux Virtual Appliance Library

Importing a previous mediawiki into TKMW

I have used this procedure more than 5 times already to save my ass reputation. I created it to migrate from an rPath wiki to TKMW and have also moved all content from an older TKMW to the latest one. With practice, you can use this to get up and running in 1 hour after a crash, if you have stored the archives created here on a different site/server. Please feel free to edit/update/improve.

How to migrate an existing mediawiki to any other mediawiki:

Note:

  1. You cannot import a mysqldump from a mediawiki v1.x to a v1.x+1. The tablespaces are different.
  2. You also need a copy of all (image) uploads from mediawiki/images/*
  3. You must use the export feature maintenance/dumpBackup.php to obtain an XML export of your current wiki
  4. Then use maintenance/importDump.php to import the XML file from the previous step
  5. This procedure DOES NOT save existing user accounts!!! These are in the MySQL dump.

Create AdminSettings.php

Logon to your current wiki server as root; make sure you have the MySQL root pwd to do the export!

cd /usr/share/mediawiki
cp /usr/share/doc/mediawiki/examples/AdminSettings.sample .

Edit the AdminSettings.sample file, add your MySQL root user details in there. Rename .sample to .php and give only root access to it:

chmod 600 AdminSettings.php

All maintenance scripts will look for these details. If you like, you can choose to add them to LocalSettings.php, but for security I choose not to.

Create XML wiki export

Now run the export:

php mediawiki/maintenance/dumpBackup.php --current --report --output=bzip2:wikiexport.xml.bz2

Create old images archive

Make an archive of mediawiki/images using your favorite tool and transfer it to your new wiki server.

tar cjf oldwiki.images.tar.bz2 /usr/share/mediawiki/images/*

Import XML wiki export

Copy both the archives to your new wiki server; repeat these steps above for creating an AdminSettings.php file on your new wiki server. Unzip the bzip2 archives (bzip2 -d <archive>)

Once you have that in place:

php mediawiki/maintenance/importDump.php wikiexport.xml

If you get errors, check your "admin" password. You should see a long listing of pages being imported.

Import old images

After importing the articles, unpack the archive of images and copy all images to a temp dir, e.g. /tmp/mywikiimages. This means you have to go through the entire directory tree from the old wiki and move/copy all of individual image files (*.jpg, *.PNG, etc) to /tmp/mywikiimages! You can import all images in one go if and only if they are all located in one single directory!

I used the following:

cd /tmp/mywikiimages
ls ?/*/*.{jpg,JPG,png,PNG,gif,GIF}
mv ?/*/*.{jpg,JPG,png,PNG,gif,GIF} .

Now all image files are in the top dir of mywikiimages. Next, import the images. But first set some access rights so mediawiki can create thumbnails, etc. Set the group to whichever user your Apache server runs as, e.g. www-data or httpd or apache, and give the group write access.

chgrp -R www-data mediawiki/images
chmod -R g+w mediawiki/images

Now we import the image files... See also Mediawiki help on this command.

php mediawiki/maintenance/importImages.php --overwrite /tmp/mywikiimport/

Now verify your LocalSettings.php is configured right. Pay extra attention to the GD/ImageMagick settings, as you are about to go a lot of image manipulation and thumbnail creation.

When all this is done, you must rebuild the wiki's internal structure:

php mediawiki/maintenance/rebuildall.php

Need more help?

Comments

When I run the: php

When I run the:

php mediawiki/maintenance/dumpBackup.php --current --report --output=bzip2:wikiexport.xml.bz2

 

I get an error:

2012-10-04 20:40:04: wiki_db 3060 pages (729.191/sec), 3061 revs (729.429/sec), ETA 2012-10-04 20:40:04 [max 3076]
Warning: Division by zero in /usr/share/mediawiki/maintenance/backup.inc on line 267

 

I opened backup.inc and wen to line 267, which is this:

function report( $final = false ) {
                if( $final xor ( $this->revCount % $this->reportingInterval == 0 ) ) {
                        $this->showReport();


 

Take out the --report parameter

There's an error in the script that dosn't warn you when using --report and missing =n parameter.

Just use the command without the --report flag.