This page explains how to backup a local MediaWiki installation to iCloud.

Create backup

I’m backing up to an iCloud folder. My MediaWiki is at /Users/jano/MediaWiki/notes and I’m going to backup to iCloud/storage/backup/localnotes.

#!/bin/bash

# Mediawiki folder to backup

SOURCE_DIR="/Users/jano/MediaWiki/notes"
mkdir -p "$SOURCE_DIR"

# Target folder where backup are stored

TARGET_DIR="/Users/jano/Library/Mobile Documents/com~apple~CloudDocs/storage/backup/localnotes"
mkdir -p "$TARGET_DIR"

echo "Backing up the website"
tar -czf "$TARGET_DIR/web_$(date +%m_%d_%y).tgz" "$SOURCE_DIR"

echo "Backing up the database"
mysqldump -u mediawiki --password=YourSecretPassword --single-transaction -B notes | gzip > "$TARGET_DIR/mysql_$(date +%m_%d_%y)_notes.gz"

echo "Finished."
open "$TARGET_DIR"
exit 0

There is a way to store the database password outside the script. Create a file ~/.my.cnf with this content:

[client]
user=mediawiki
password=YourSecretPassword
host=localhost

Ensure only your user can read it:

chmod 600 ~/.my.cnf

In mysqldump replace --password=YourSecretPassword with --defaults-file=~/.my.cnf.

Restore backup

Restore the database:

sudo mysql -u root
# Restore the database backup. This will create a database called 'notes'.
SOURCE mysql_09_22_23_notes;

# Create a user. This should match the user in LocalSettings.php
CREATE USER 'mediawiki'@'localhost' IDENTIFIED BY 'MySecretPassword';
GRANT ALL PRIVILEGES ON notes.* TO 'mediawiki'@'localhost' WITH GRANT OPTION;

EXIT

If you have a previous version, copy the whole folder:

rm -rf /Users/jano/MediaWiki/notes/
rsync -av /Users/jano/Developer/backup_rsync/www/notes/ /Users/jano/MediaWiki/notes/
cd /Users/jano/MediaWiki/notes/
Update PHP dependencies using Composer:

cd /Users/jano/MediaWiki/notes/
brew install composer 
composer update --no-dev

Relocate folder

If you need to relocate the MediaWiki installation to a different folder, edit the following.

In notes/LocalSettings.php:

$wgDebugLogFile = "/Users/jano/MediaWiki/debug.log";
$wgUploadDirectory = "/Users/jano/MediaWiki/notes/images";
In httpd.conf:

DocumentRoot "/Users/jano/MediaWiki/notes"
<Directory "/Users/jano/MediaWiki/notes">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

Upgrade MediaWiki

To upgrade MediaWiki you have to replace the folder with the last version, but first you need to backup the following files:

images/
fonts/
favicon.ico
LocalSettings.php

After the installation, you need to compare the old LocalSettings.php with the backup version and copy back the customizations. I could move the custom section to an additional file, but I rather review the whole thing.

For more questions, see also MediaWiki FAQ.