Media Wiki Backup Automation

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

This page documents the Media Wiki automated backup procedure. Once the tooling is deployed, it will periodically produce and store a backup file that can be used to fully restore a Media Wiki instance by following the Media Wiki Restoration procedure.

Media Wiki Instance Backup Script

A backup script that introspects the mediawiki instance, performs a full backup (database, files, extensions, configuration) and produces a file that can be used to fully restore the Media Wiki instance:

mediawiki-backup

The script has in-line help, but essentially the backup is as simple as:

mediawiki-backup /var/www/mediawiki-1.35.0

Set up Backup Automation

The backup mechanism consists of two parts: a backup script run periodically with cron on the MediaWiki host and takes snapshots of the database and the file system, and another script run with cron on the NAS server that pulls the backup files and stores them. We opted to go for this solution and not a NFS filesystem mounted on the MediaWiki server because we wanted to completely isolate the MediaWiki host from the NAS server - NAS knows about the MediaWiki server but the MediaServer wiki does not know anything about the NAS server.

MediaWiki Server Backup Setup

Install the Backup Script

As root, check out shell-tools in /root:

cd /root
git clone https://github.com/ovidiuf/shell-tools.git

Smoke test:

/root/shell-tools/backup-system/mediawiki-backup version
0.2.2

Create the backup executable wrapper to be invoked by cron, which contains site-specific customizations. When choosing the mediawiki-backup target directory, make sure not to use a symbolic link, but the mediawiki directory itself.

mkdir /root/bin

Create a /root/bin/backup-site with the following content:

#!/usr/bin/env bash
source_dir=/var/www/mediawiki-1.35.0
date >> /root/log/backup.log 
/root/shell-tools/backup-system/mediawiki-backup ${source_dir} -t /root/backups >> /root/log/backup.log 2>&1
chgrp servicegroup /root/backups/*
chmod g+w /root/backups/*

Then:

chmod a+x /root/bin/backup-site

Create the backup and the cron log directory:

mkdir /root/backups
mkdir /root/log

Configure the backup script with the correct source_dir path.

Test the backup script:

cd /tmp
/root/bin/backup-site

It should create a backup file in /root/backups and a log record in /root/log.

Configure cron to run the Backup Script

Follow cron configuration instructions from here:

Simple cron Job

This is the crontab file, the backup script will be run every morning at 3:00 AM:

0 3 * * * /root/bin/backup-site

More details:

Cron

Legacy Backup Script

backup-wiki-locally has been made obsolete by mediawiki-backup.

Configure the NAS Server to Periodically Pull Backup Files

Setup the Script

As root:

mkdir -p /volume4/backups/bin

and place pull-kb.novaordis.com-backup in /volume4/backups/bin. Make it executable by root.

This is a pull-kb.novaordis.com-backup example.

Build and install bakm in the same /volume4/backups/bin directory.

Also create /volume4/backups/bin/backup_operator_identity-id_rsa and place the corresponding public key into the ~/.ssh/authorized-keys of the account that handles the local backup on the other end.

Setup the Task

This procedure applies to a Synology NAS station, for more details see Synology NAS Procedures - Schedule a Task.

Control Panel → System → Task Scheduler → Create → User-defined script.

Task: "kb.novaordis.com Backup"

User: root

Enabled

Run command: /volume4/backups/bin/pull-kb.novaordis.com-backup

If the backup on the target host is scheduled at 3:00 AM, schedule this one at 3:30 AM: Schedule → Run on the following days: Daily, Time. First Run time: 3:30, Frequency: once a day. Last run time: 03:30.