Media Wiki Backup Automation: Difference between revisions
(5 intermediate revisions by the same user not shown) | |||
Line 11: | Line 11: | ||
=Media Wiki Instance Backup Script= | =Media Wiki Instance Backup Script= | ||
A backup script that introspects the | 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'> | ||
Line 19: | Line 19: | ||
=<span id='Set_up_Backup'></span>Set up Backup Automation= | =<span id='Set_up_Backup'></span>Set up Backup Automation= | ||
The backup mechanism consists of two parts: a backup script | 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=== | ===Install the Backup Script=== | ||
As root, check out <code>shell-tools</code> in <code>/root</code>: | |||
As root, check out shell-tools in <code>/root</code>: | |||
<syntaxhighlight lang='bash'> | <syntaxhighlight lang='bash'> | ||
Line 32: | Line 29: | ||
</syntaxhighlight> | </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'> | <syntaxhighlight lang='bash'> | ||
/root/shell-tools/backup-system/mediawiki-backup version | /root/shell-tools/backup-system/mediawiki-backup version | ||
0. | 0.3.0 | ||
</syntaxhighlight> | </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 | 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'> | <syntaxhighlight lang='bash'> | ||
mkdir /root/bin | mkdir /root/bin | ||
Line 46: | Line 49: | ||
#!/usr/bin/env bash | #!/usr/bin/env bash | ||
source_dir=/var/www/mediawiki-1.35.0 | source_dir=/var/www/mediawiki-1.35.0 | ||
date >> /root/log/backup.log | 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 | /root/shell-tools/backup-system/mediawiki-backup ${source_dir} -t /root/backups >> /root/log/backup.log 2>&1 | ||
chgrp | chgrp ${service_group} /root/backups/* | ||
chmod g+w /root/backups/* | chmod g+w /root/backups/* | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 86: | Line 91: | ||
More details: {{Internal|Cron|Cron}} | More details: {{Internal|Cron|Cron}} | ||
==Configure the NAS Server to Periodically Pull Backup Files== | ==Configure the NAS Server to Periodically Pull Backup Files== |
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:
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:
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:
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.