Mediawiki back up and restore steps

From Wiki at Neela Nurseries
Jump to: navigation, search

MediaWiki Back-up Process
Started: 2016-04-12 Tuesday



Overview

Note: this article is in progress! This article aims to cover back-up and recovery steps of a personal or small-scale Mediawiki site.

This article describes the situation where the wiki to restore is supported by and running on a Linux based host, and the target host to support the back up copy of the wiki is also a Linux based host.


Supporting Pieces for Localhost Mediawiki Config:

  • Install latest Ubuntu LTS server, or Linux distro of choice
  • Install Xserver and window manager of choice
  • Install apache2 webserver
  • Install latest PHP 7.x or 8.x version
  • Enable SSL module for apache2, e.g. invoke `sudo a2enmod ssl.load` and restart apache2
  • Create self-signed certificate and private key, store in /etc/apache2/ssl
  • Create web document root directory for local sandbox / test site, e.g. /var/www/sandbox-website.local
  • Amend /etc/hosts with stanza corresponding to local test site, e.g. `127.0.0.1 sandbox-website.local`
  • Create an apache2 virtual hosts file for local testing website
  • Create an index.html or index.php file in `/var/www/sandbox-website.local/public_html`


TODO:

(1) note test `netstat -ntulp` to confirm at least one service listening on SSL port 443

(2) note amendment to /etc/apache2/ports.conf to enable localhost apache2 server to listen on port 8000


MYSQL server, MYSQL client and Mediawiki:

  • Install the latest stable MYSQL server and client on the computer which will host the wiki back up,
  • Create a database for the wiki and a MYSQL user with password and privileges to the new database,
  • Download and uncompress latest stable release of mediawiki,
  • Rename uncompressed mediawiki top directory to short name such as 'wiki',
  • For remote configuration via browser move this renamed mediawiki file set to /var/www/html,
  • Complete the seven to ten steps via Mediawiki's web interface found in the mw-config subdirectory,
  • Copy media files from the original wiki to the path defined in $wgUploadPath,
  • Use a web browser and navigate through several pages of the restored wiki on the newer target host.


When downloading MediaWiki, use GNU Privacy Guard or gpg utility to confirm that the downloaded files are integral. See MediaWiki public keys page for command to issue to obtain public gpg keys.

The question now is how many of these steps can be automated in a shell script? . . . - TMH


Creating Wiki Database And Wiki User


ted@back-up-server:/var/www/wiki$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)

Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.04 sec)

mysql> CREATE DATABASE wikidb;
Query OK, 1 row affected (0.03 sec)

mysql> grant all privileges on wikidb.* to 'wikiuser'@'localhost' identified by 'wiki_pass_phrase';
Query OK, 0 rows affected, 1 warning (0.03 sec)



Wiki Database Back Up


$ mysqldump -h localhost -u wikiuser -p --default-character-set=utf8 wikidb >> /home/ted/local-wiki-database-backup-2016-05-03.sql

This file may be gzip'd or otherwise compressed. In the case of our example wiki, compression reduces database file size from 148 MB to 36 MB, about a four fold reduction in file size.


MediaWiki download, verify and install

It is a good idea to download the latest stable release of MediaWiki from MediaWiki's downloads page, and to verify that your downloaded instances of this software pass GNU php signature / key checks. GNU Privacy Guard how-to page has some good tutorial info on how to verify gpg-signed files.

Once MediaWiki version x is downloaded and uncompressed, there is a single parent directory of our MediaWiki instance which at this point we may rename and move into its web root directory. A generic name for a MediaWiki installation on a webserver might be something like "wiki". We may rename, for example, the later 2017 release candidate mediawiki-1.30.0-rc.0 --> wiki, and move this file then to a typical web directory like /var/www/html. At this point the local web server apache2 or nginx doesn't know anything about the newly downloaded, verified, uncompressed and unarchived MediaWiki software. We must add a couple of config files belonging to the web server.

For apache2 web server, a simple way to inform the web server of the new page we want to provide to the world wide web ( or local area network ) is to create a configuration file per apache2's understood file formats. The locations of the text file for a web domain or web site, and a conventional symlink to enable the given website are:


  /etc/apache2/sites-available/given-site.conf
  /etc/apache2/sites-enabled/000-given-site.conf --> ../sites-available/given-site.conf


Wiki Database Restoration

At least some of the time the MYSQL database dump file will have in the first several lines a comment expressing the database which is backed up by the given file. There may not, however, be any MYSQL statement to create a database by that name, or to use a database by that name. One of these MYSQL directives will likely need be added manually to the file before invoking the MYSQL client to run the statements contained in the back up file.


Figure x - first twenty lines of a MYSQL database back up file:


user@localhost:~/archive$ cat local-wiki-database-backup-2016-12-28.sql | head -n 20

-- MySQL dump 10.13  Distrib 5.1.54, for debian-linux-gnu (x86_64)
--
-- Host: localhost    Database: wikidb
-- ------------------------------------------------------
-- Server version       5.1.54-1ubuntu4

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `archive`
--


Database dumps can be redirected at the shell prompt to the MYSQL client:


  $ mysql [database_name] < database-back-up.sql


http://dev.mysql.com/doc/refman/5.5/en/mysql-batch-commands.html



Restoring Media Files

While the wiki database may be large on the order of tens or hundreds of megabytes, the media files such as PDFs, images, videos and audio clips are not embedded in the database. These files are organized in a wiki directory defined by the LocalSettings.php variable named $wgUploadPath.

As of 2017-10-04 WED the third and final command below is sufficient to copy media files from the wiki to be backed up and restored to the new target wiki:


Figure x - using rsync to back up and restore media files of a wiki site:


ted@back-up-server:/var/www/html/wiki/images$ date
Tue Jan  3 18:45:40 PST 2017

ted@back-up-server:/var/www/html/wiki/images$ pwd
/var/www/html/local-wiki/images

ted@back-up-server:/var/www/html/wiki/images$ rsync -avzpt ted@original-server:/var/www/wiki/images/* .


References



- top of page -