Media Wiki Backup Automation: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
m (Ovidiu moved page Media Wiki Backing Up to Media Wiki Back Up without leaving a redirect)
 
(12 intermediate revisions by the same user not shown)
Line 8: Line 8:


=Overview=
=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#Overview|Restoring a Wiki into the Same or Newer MediaWiki Version]] procedures.
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#Overview|Media Wiki Restoration]] procedure.


=MediaWiki Server Backup Script=
=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 restore the wiki: {{External|[https://github.com/ovidiuf/shell-tools/blob/master/backup-system/mediawiki-backup mediawiki-backup]}}
A backup script that introspects the Media Wiki instance, performs a full backup (database, files, extensions, configuration) and produces a file that can be used to fully restore the Media Wiki instance: {{External|[https://github.com/ovidiuf/shell-tools/blob/master/backup-system/mediawiki-backup mediawiki-backup]}}
The script has in-line help, but essentially the backup is as simple as:
The script has in-line help, but essentially the backup is as simple as:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
mediawiki-backup /var/www/mediawiki-1.35.0
mediawiki-backup /var/www/mediawiki-1.35.0
</syntaxhighlight>
</syntaxhighlight>
==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]}}
=<span id='Set_up_Backup'></span>Set up Backup Automation=
=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 that is periodically executed by cron on the Media Wiki host and that takes snapshots of the database and the file system (<code>mediawiki-backup</code>), and another script that is periodically executed by 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 Media Wiki host from the NAS server. The NAS server knows about the Media Wiki server but the Media Wiki does not know anything about the NAS server.
==Media Wiki Server Backup Setup==
===Install the Backup Script===
As root, check out <code>shell-tools</code> in <code>/root</code>:
 
<syntaxhighlight lang='bash'>
cd /root
git clone https://github.com/ovidiuf/shell-tools.git
</syntaxhighlight>
 
If the repository is already present, pull the latest version:
<syntaxhighlight lang='bash'>
cd /root/shell-tools
git pull
</syntaxhighlight>
 
Verify the version:
<syntaxhighlight lang='bash'>
/root/shell-tools/backup-system/mediawiki-backup version
0.3.0
</syntaxhighlight>
 
Create the backup executable wrapper to be invoked by cron, which contains site-specific customizations. When choosing the <code>mediawiki-backup</code> target directory, make sure not to use a symbolic link, but the Media Wiki 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
service_group=au739kr60b
 
date >> /root/log/backup.log
/root/shell-tools/backup-system/mediawiki-backup ${source_dir} -t /root/backups >> /root/log/backup.log 2>&1
chgrp ${service_group} /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}}
 
==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.

Latest revision as of 00:05, 31 December 2023

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 Media Wiki 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 that is periodically executed by cron on the Media Wiki host and that takes snapshots of the database and the file system (mediawiki-backup), and another script that is periodically executed by 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 Media Wiki host from the NAS server. The NAS server knows about the Media Wiki server but the Media Wiki does not know anything about the NAS server.

Media Wiki 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

If the repository is already present, pull the latest version:

cd /root/shell-tools
git pull

Verify the version:

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

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 Media Wiki 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
service_group=au739kr60b

date >> /root/log/backup.log
/root/shell-tools/backup-system/mediawiki-backup ${source_dir} -t /root/backups >> /root/log/backup.log 2>&1
chgrp ${service_group} /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

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.