Media Wiki Backup Automation: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
m (Ovidiu moved page Media Wiki Back Up to Media Wiki Backup without leaving a redirect)
Line 18: Line 18:
==Legacy Script==
==Legacy Script==
Reference kb.novaordis.com backup script (deprecated now): {{External|[https://github.com/ovidiuf/shell-tools/blob/master/backup-system/backup-kb.novaordis.com backup-kb.novaordis.com]}}
Reference kb.novaordis.com backup script (deprecated now): {{External|[https://github.com/ovidiuf/shell-tools/blob/master/backup-system/backup-kb.novaordis.com backup-kb.novaordis.com]}}
=Set up Backup Automation=
=<span id='Set_up_Backup'></span>Set up Backup Automation=
{{Internal|Media_Wiki_Native_Installation#Set_up_Backup_Automation|MediaWiki Native Installation &#124; 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 <code>/root</code>:
 
<syntaxhighlight lang='bash'>
cd /root
git clone https://github.com/ovidiuf/shell-tools.git
</syntaxhighlight>
 
Smoke test:
<syntaxhighlight lang='bash'>
/root/shell-tools/backup-system/mediawiki-backup version
0.2.2
</syntaxhighlight>
 
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.
<syntaxhighlight lang='bash'>
mkdir /root/bin
</syntaxhighlight>
Create a <code>/root/bin/backup-site</code> with the following content:
<syntaxhighlight lang='bash'>
#!/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/*
</syntaxhighlight>
Then:
<syntaxhighlight lang='bash'>
chmod a+x /root/bin/backup-site
</syntaxhighlight>
 
Create the <code>backup</code> and the cron <code>log</code> directory:
 
<syntaxhighlight lang='bash'>
mkdir /root/backups
mkdir /root/log
</syntaxhighlight>
 
Configure the backup script with the correct <code>source_dir</code> path.
 
Test the backup script:
 
<syntaxhighlight lang='bash'>
cd /tmp
/root/bin/backup-site
</syntaxhighlight>
 
It should create a backup file in <code>/root/backups</code> and a log record in <code>/root/log</code>.
 
===Configure cron to run the Backup Script===
 
Follow cron configuration instructions from here:
{{Internal|cron#Simplest_cron_Job|Simple cron Job}}
 
This is the <tt>crontab</tt> file, the backup script will be run every morning at 3:00 AM:
 
<syntaxhighlight lang='text'>
0 3 * * * /root/bin/backup-site
</syntaxhighlight>
 
More details: {{Internal|Cron|Cron}}
 
===Legacy Backup Script===
 
[[backup-wiki-locally]] has been made obsolete by [https://github.com/ovidiuf/shell-tools/blob/master/backup-system/mediawiki-backup mediawiki-backup].
 
==Configure the NAS Server to Periodically Pull Backup Files==
 
===Setup the Script===
 
As <code>root</code>:
 
<syntaxhighlight lang='bash'>mkdir -p /volume4/backups/bin</syntaxhighlight>
 
and place <code>pull-kb.novaordis.com-backup</code> in <code>/volume4/backups/bin</code>. Make it executable by <code>root</code>.
 
This is a [[pull-kb.novaordis.com-backup]] example.
 
Build and install [[bakm]] in the same <code>/volume4/backups/bin</code> directory.
 
Also create <code>/volume4/backups/bin/backup_operator_identity-id_rsa</code> and place the corresponding public key into the <code>~/.ssh/authorized-keys</code> 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 Procedure Schedule a Task|Synology NAS Procedures - Schedule a Task]].
 
Control Panel → System → Task Scheduler → Create → User-defined script.
 
Task: "kb.novaordis.com Backup"
 
User: <code>root</code>
 
Enabled
 
Run command: <code>/volume4/backups/bin/pull-kb.novaordis.com-backup</code>
 
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.

Revision as of 19:55, 30 December 2023

External

Internal

Overview

This procedure produces a file that can then be used as part of the Restoring a Wiki into the Same or Newer MediaWiki Version procedures.

MediaWiki Server 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 restore the wiki:

mediawiki-backup

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

mediawiki-backup /var/www/mediawiki-1.35.0

Legacy Script

Reference kb.novaordis.com backup script (deprecated now):

backup-kb.novaordis.com

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.