Saturday, February 14, 2009

Mirroring a mediawiki to another server

There are lots of good guides on the interwebs on how to do this but I wanted to get a few notes down so I remember my preferred/installed method. These instructions are for Debian/Ubuntu and assume the target server doesn't have an existing mediawiki or mysql installation. All this needs to be done as root.

1. Install mediawiki on the target server, install the same version.

2. Delete /var/lib/mediawiki1.7 on the target server.

3. Dump the mysql permissions database on the source server:

mysqldump -u root -pYOURPASSWORD --opt mysql > ~/mysql.sql

4. Copy that file over to the target file. Import it using the following command.

mysql -pYOURPASSWORD -h mysql < ~/mysql.sql

5. Setup a cron job on the source host to dump the mediawiki sql database every night. Type crontab -e to edit the crontab and add the following line:

0 0 * * * mysqldump -u root -pYOURPASSWORD --opt wikidb > ~/wikidb.sql

6. On the target host, add cron jobs to copy across the database dump, the mediawiki config/uploaded files and to import the mediawiki database. Again do crontab -e and add the following:

0 5 * * *  rsync -oglpvtr root@SOURCEHOST:/var/lib/mediawiki1.7 /var/lib > ~/backups/SOURCEHOST_mediawiki.log
0 5 * * * rsync -vtr root@SOURCEHOST:/root/wikidb.sql ~/wikidb.sql
0 6 * * * mysql -pYOURPASSWORD -h wikidb < ~/wikidb.sql

Protip: you'll need your ssh keys setup so you can do passwordless authentication.

No comments: