Skip to content

MediaWiki Backups & Maintenance — Keeping Your Wiki Safe

DodaTech Updated 2026-06-26 6 min read

In this tutorial, you'll learn how to back up and maintain your MediaWiki wiki. This is Lesson 9 of our project: Build Your Own Documentation Wiki.

What You'll Build Today

By the end of this lesson, you will have:

  • A complete backup of your wiki (database + files)
  • An XML export of all your pages
  • A restoration test (proving your backup works)
  • Your wiki set up with basic Caching for better speed

Your wiki is now not just feature-rich, but safe.

Why Backups Matter

Imagine spending days creating wiki content, templates, and extensions. Then your hard drive fails, or a database corruption wipes everything out.

A backup is your insurance policy. With a proper backup, you can restore your wiki in minutes. Without one, you start from zero.

MediaWiki stores data in two places:

What Where Backup Method
Page content, users, settings MySQL database mysqldump or XML export
Images, skins, extensions File system Zip or tar of the folder
Configuration LocalSettings.php Copy this file separately

Step-by-Step: Back Up Your Wiki

Step 1: Back Up the Database

The database contains all your page content, user accounts, and settings. This is the most important backup.

Using mysqldump (recommended):

Open a terminal and run:

# Windows (from XAMPP shell)
"C:\xampp\mysql\bin\mysqldump" -u root mediawiki > mediawiki_db_2026-06-26.sql

# Linux/macOS
mysqldump -u root mediawiki > ~/backups/mediawiki_db_2026-06-26.sql

This creates a SQL file containing all your wiki's data. The file is human-readable — you can open it in a text editor and see your pages as SQL INSERT statements.

â„šī¸ Info

If you set a database password during installation, add -p to the command. It will prompt you for the password:

mysqldump -u root -p mediawiki > backup.sql

Step 2: Back Up the Files

The file system contains images, skins, extensions, and your configuration.

# Create a backup of the entire mediawiki folder (excluding cache)
tar -czf ~/backups/mediawiki_files_2026-06-26.tar.gz \
  --exclude="cache" \
  /opt/lampp/htdocs/mediawiki

Alternatively, copy the folder:

cp -r /opt/lampp/htdocs/mediawiki ~/backups/mediawiki_files_2026-06-26

Don't forget LocalSettings.php:

This file is so important that it deserves its own backup:

cp /opt/lampp/htdocs/mediawiki/LocalSettings.php \
   ~/backups/LocalSettings_2026-06-26.php

Step 3: Export Pages as XML

The SQL backup is comprehensive, but XML export is more portable. You can import the XML into any MediaWiki installation — even on a different server.

  1. Go to Special:Export on your wiki
  2. In the text box, add all your page names, one per line:
Main Page
Project Setup Guide
API Reference
Troubleshooting Common Errors
Template:Note
Template:Infobox Software
User:YourUsername
Help:Editing
Module:Hello
Template:Hello
Template:Greeting
  1. Check these options:

    • ☑ Include only the current revision (faster)
    • ☐ Include templates (uncheck for now)
    • ☐ Save as file (this downloads the XML)
  2. Click "Export"

The downloaded XML file contains all your pages in a standard format. This file can be imported into any MediaWiki wiki using Special:Import.

Step 4: Test Your Backup (Restore Into a Second Wiki)

A backup you never test is not a backup. Let's prove yours works by restoring into a second MediaWiki installation.

  1. Install a second MediaWiki instance at http://localhost/mediawiki_test (repeat Lesson 2 with a different database name, e.g., mediawiki_test)

  2. Import your XML file:

    Go to http://localhost/mediawiki_test/index.php/Special:Import

    Select your XML file and click "Import"

  3. Check that your pages are there — visit each one

  4. If they all appear with correct content, your backup is valid

âš ī¸ Warning

The XML export only contains page content. It does NOT include user accounts, extensions, or LocalSettings.php. For a full restore, you need the SQL backup AND the file backup.

Step 5: Set Up Basic Caching

MediaWiki can be slow without caching, especially as your wiki grows. Here's how to speed it up.

Enable file cache:

Add to LocalSettings.php:

$wgMainCacheType = CACHE_ANYTHING;
$wgUseFileCache = true;
$wgFileCacheDirectory = "$IP/cache";

This stores rendered pages as static HTML files. Subsequent visits load the cached version instead of querying the database.

Enable object caching (APCu):

If PHP has the APCu extension, add:

$wgMainCacheType = CACHE_ACCEL;

This caches PHP objects in memory, making page loads even faster.

â„šī¸ Info

APCu is usually included with XAMPP but might need to be enabled in php.ini. Look for extension=apcu and remove the semicolon at the start of the line.

Step 6: Create a Backup Schedule

Manual backups are easily forgotten. Set up a schedule:

Linux/macOS — Add a cron job:

# Edit crontab
crontab -e

# Add this line (runs every Sunday at 3 AM)
0 3 * * 0 mysqldump -u root mediawiki > ~/backups/weekly/wiki_$(date +\%Y-\%m-\%d).sql

Windows — Use Task Scheduler:

  1. Open Task Scheduler
  2. Create a new task that runs weekly
  3. Action: Start a program → C:\xampp\mysql\bin\mysqldump.exe
  4. Arguments: -u root mediawiki > C:\backups\wiki_%DATE%.sql

What You Learned

  • mysqldump backs up the database (page content, users, settings)
  • File backup saves images, extensions, and LocalSettings.php
  • XML export creates portable page dumps
  • Always test your backups by restoring to a fresh wiki
  • Caching improves page load speed significantly
  • Automated backups prevent data loss

In the next lesson, we'll cover common problems and their solutions.

Common Errors

Error Why It Happens How to Fix
mysqldump: command not found MySQL binaries aren't in your PATH Use the full path: C:\xampp\mysql\bin\mysqldump.exe on Windows or /opt/lampp/bin/mysqldump on Linux.
"Access denied" when running mysqldump Wrong database credentials If you set a password, use -p and enter the password. The default XAMPP root user has no password.
Import fails with "The page already exists" You need to allow overwriting Check "Include only the current revision" and "Import as a new page if the target page already exists" in Special:Import. Or delete the existing pages first.
Caching doesn't seem to work Cache directory is not writable Make sure the cache folder exists and is writable by the web server: mkdir -p /opt/lampp/htdocs/mediawiki/cache && chmod 777 /opt/lampp/htdocs/mediawiki/cache
"Failed to open stream: No such file or directory" Wrong path in a backup script Double-check all paths in your backup commands. Use absolute paths (starting with / on Linux, C:\ on Windows).
XML export is empty No pages selected Make sure you typed the page names correctly. Use "Add all pages" if you want everything.

FAQ

How often should I back up?

At minimum: weekly database backups, daily if your wiki has active contributors. File backups can be less frequent (monthly) since files change rarely.

Do I need to stop the wiki before backing up?

For mysqldump, you don't need to stop the wiki — the dump is consistent enough for most wikis. For maximum safety, you can put the wiki in read-only mode during backup by adding $wgReadOnly = "Backup in progress — will be back in a few minutes"; to LocalSettings.php.

Can I back up to cloud storage?

Yes. After creating the backup files, upload them to cloud storage:

# Using rclone (works with Google Drive, Dropbox, S3, etc.)
rclone copy ~/backups/mediawiki_db_2026-06-26.sql gdrive:wiki-backups/

How do I upgrade MediaWiki to a new version?

  1. Back up everything (database + files)
  2. Download the new MediaWiki version
  3. Replace the old files with the new ones (keep LocalSettings.php and extensions/)
  4. Run the upgrade script: http://localhost/mediawiki/maintenance/update.php
  5. Visit Special:Version to confirm the upgrade

My wiki is slow. What should I check first?

  1. Enable file cache (covered above)
  2. Check if MySQL is using too much memory
  3. Disable extensions you don't need
  4. Upgrade to the latest MediaWiki version (performance improves with each release)

What's Next

You now know how to keep your wiki safe and fast. But even with the best maintenance, problems happen.

Continue to Lesson 10: Common Errors & FAQ — a comprehensive reference for solving the most common MediaWiki problems.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro