MediaWiki Backup And Restore

From MediaWiki
Jump to navigationJump to search

Backup

The system which contains the NST WIKI performs nightly backups. The compressed back up files under the /var/nst/nstwiki_archive directory.

The /var/nst/nstwiki_archive directory is then mirrored at external locations.

The following items are backed up:

  • The SQL database associated with the Wiki.
  • The configuration files associated with the Wiki.
  • The media files (images) associated with the Wiki.

Here is an example of using rsync to download a copy of the back up files:

[root@cirrus ~]# rsync -rp nstwiki:/var/nst/nstwiki_archive /tmp/
[root@cirrus ~]# ls -l /tmp/nstwiki_archive
total 198476
-rw-r--r--. 1 root root  66375294 2011-10-22 18:18 nstwiki_conf_archive0.tgz
-rw-r--r--. 1 root root 126201929 2011-10-22 18:18 nstwiki_media_archive0.tgz
-rw-r--r--. 1 root root  10654681 2011-10-22 18:18 nstwiki_rpm_archive0.tgz
[root@cirrus ~]# 

Restore/Move

If you need to restore the NST Wiki or need to relocate the NST Wiki to another machine, use the following strategy:

  • Set up MediaWiki on the other machine by following the instructions on the MediaWiki page.
  • Stop the httpd service.
  • Stop the mysqld service.
  • Transfer and install from the back up archives.
  • Start the mysqld service.
  • Run any new MediaWiki database upgrade scripts (if you are moving to a newer version of MediaWiki).
  • Update your LocalSettings.php file.
  • Start the httpd service.

Set Up MediaWiki

If you are moving the NST Wiki to a new machine, you will need to set up MediaWiki on the new machine:

  • Before setting up MediaWiki, review the LocalSettings.php file as you will likely want to match some of the settings (if you don't it's not the end of the world - but if you take the time now it might save you some tweaks later).
  • See the MediaWiki page for details on setting up MediaWiki on a NST system.
  • Install the EmbedVideo media extension.

Stop Services

Stop the httpd and mysqld services as shown below (use service instead of systemctl if you are on a older system):

[root@probe-p3p1 ~]# systemctl stop httpd.service
[root@probe-p3p1 ~]# systemctl stop mysqld.service
[root@probe-p3p1 ~]# 

Transfer And Extract The Backup Archives

Get a copy of the NST Wiki backup files from the directory /var/nst/nstwiki_archive directory and transfer them to your /tmp directory:

[root@probe-p3p1 ~]# rsync -rp nstwiki:/tmp/nstwiki_archive /tmp/
root@nstwiki's password: 
[root@probe-p3p1 ~]# ls -l /tmp/nstwiki_archive
total 198476
-rw-r--r-- 1 root root  66375294 Oct 22 18:32 nstwiki_conf_archive0.tgz
-rw-r--r-- 1 root root 126201929 Oct 22 18:32 nstwiki_media_archive0.tgz
-rw-r--r-- 1 root root  10654681 Oct 22 18:32 nstwiki_rpm_archive0.tgz
[root@probe-p3p1 ~]# 

Make a backup copy of the working LocalSettings.php file on your new MediaWiki installation.

[root@probe-p3p1 ~]# cp /var/www/wiki/LocalSettings.php LocalSettings.php.working

Extract the contents of the nstwiki_conf_archive0.tgz file to the /var/nst/backup directory:

[root@probe-p3p1 ~]# install -d /var/nst/backup
[root@probe-p3p1 ~]# tar xzf /tmp/nstwiki_archive/nstwiki_conf_archive0.tgz -C /var/nst/backup/ .
[root@probe-p3p1 ~]# 

Extract the contents of the nstwiki_media_archive0.tgz file to the directory where your MediaWiki files live. This location will depend on your configuration.

[root@probe-p3p1 ~]# tar xzf /tmp/nstwiki_archive/nstwiki_media_archive0.tgz -C /var/nst/mediawiki
[root@probe-p3p1 ~]# 

Extract the nst skins from the nstwiki_rpm_archive0.tgz to the /usr/share/mediawiki directory. Be careful! Limit the extraction to just the files matching "./skins/nst/*":

[root@probe-p3p1 ~]# tar xzf /tmp/nstwiki_archive/nstwiki_rpm_archive0.tgz -C /usr/share/mediawiki/ "./skins/nst/*"
[root@probe-p3p1 ~]#

Restore The NST Wiki Database

At this point you can start up the mysqld service and restore the most recent version of the NST Wiki backup. However, before you can restore using the SQL file you will need to drop the wikidb (or whatever you named your database) if it exists:

[root@probe-p3p1 ~]# systemctl start mysqld.service
[root@probe-p3p1 ~]# mysql -h 127.0.0.1 --user=root --password
Enter password:  
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.14 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> drop database wikidb;
Query OK, 45 rows affected (0.15 sec)

mysql> \q
Bye
[root@probe-p3p1 ~]# 

At this point you can restore the NST Wiki database:

[root@probe-p3p1 ~]# gzip -dc < /var/nst/backup/db/nstwikidb.sql.gz | mysql -h 127.0.0.1 --user=root --password
Enter password: 
[root@probe-p3p1 ~]#

Update The NST Wiki Database

If the location you are restoring the database to uses a newer version of MediaWiki, you will likely need to run the MediaWiki upgrade commands. Review the /usr/share/doc/mediawiki/UPGRADE file. Most likely you will need to run the following commands:

[root@probe-p3p1 ~]# cd /usr/share/mediawiki/maintenance/
[root@probe-p3p1 maintenance]# php update.php 
A copy of your installation's LocalSettings.php
must exist and be readable in the source directory.
[root@probe-p3p1 maintenance]# php update.php --conf /var/nst/mediawiki/LocalSettings.php
MediaWiki 1.16.5 Updater

Going to run database updates for wikidb
Depending on the size of your database this may take a while!

... Lot's of output as database is updated ...

Purging caches...done.
Done.
[root@probe-p3p1 maintenance]# cd
[root@probe-p3p1 ~]#

Update LocalSettings.php

Before starting up the web server, you will want to review your LocalSettings.php file:

  • Compare it with the back up you made earlier (/root/LocalSettings.php.working).
  • Initially disable any extensions currently configured (you may need to install the extension modules before enabling).
  • Review the contents of /usr/share/mediawiki/includes/DefaultSettings.php to see if there are any new settings you need to add.
[root@probe-p3p1 ~]# emacs -nw /var/nst/mediawiki/LocalSettings.php LocalSettings.php.working
[root@probe-p3p1 ~]#

Restart The Web Service And Test

At this point you should be able to restart the web service and test your installation:

[root@probe-p3p1 ~]# systemctl start httpd.service
[root@probe-p3p1 ~]# firefox http://127.0.0.1/wiki
[root@probe-p3p1 ~]#

At this point you should be able to review the contents of the Wiki and determine what is broken (not working) and then try to figure out what you need to do in the /var/www/wiki/LocalSettings.php file to get it working again.