Manual:Backing up a wiki

It is important to make regular backups of the data in your wiki. This page provides an overview of the backup process for a typical MediaWiki wiki; you will probably want to devise your own backup scripts or schedule to suit the size of your wiki and your individual needs.

Overview
MediaWiki stores important data in two places:
 * Database : Pages and their contents, users and their preferences, metadata, search index, etc.
 * File system : Software configuration files, custom skins, extensions, images (including deleted images), etc.

Consider making the wiki read-only before creating the backup - see $wgReadOnly. This makes sure all parts of your backup are consistent (some of your installed extensions may write data nonetheless).

File transfer
You will have to choose a method for transferring files from the server where they are:


 * Non-private data you can simply [https://github.com/WikiTeam/wikiteam/wiki/Tutorial#Publishing_the_dump publish on archive.org] and/or in a  directory of your webserver.
 * SCP (or WinSCP), SFTP/FTP or whatever other transfer protocol you're used to/is available.
 * The hosting company might provide a file manager interface via a web browser; check with your provider.

Database
Most of the critical data in the wiki is stored in the database, which is typically straightforward to back up. When using the default MySQL backend, the database can be dumped into a script file which can be used later to recreate the database and all the data in it from scratch.


 * 1) apt install automysqlbackup

PostgreSQL
You can use the  tool to back up a MediaWiki PostgreSQL database. For example: pg_dump mywiki > mywikidump.sql

will dump the  database to mywikidump.sql.

To restore the dump: psql mywiki -f mywikidump.sql

You may also want to dump the global information, e.g. the database users:

pg_dumpall --globals > postgres_globals.sql

phpMyAdmin
Turn your wiki to read only by adding  to LocalSettings.php.

Open the browser to your phpadmin link, login, choose the wiki database. (Check LocalSettings.php if you're not sure). Select Export. Make sure all items under Export are highlighted, and make sure Structure is highlighted (it's important to maintain the table structure). Optionally check Add DROP TABLE to delete existing references when importing. Make sure Data is checked. Select zipped. Then click on GO and save the backup file.

Remove  from LocalSettings.php

Remember to also backup the file system components of the wiki that might be required, eg. images, logo, and extensions.

HeidiSQL
[http://www.heidisql.com/ HeidiSQL] is similar to phpMyAdmin, but without any restrictions of phpMyAdmin's free version.

HeidiSQL requires a direct database connection, where some hosts may only offer web interfaces (phpMyAdmin) to firewalled databases.

File system
MediaWiki stores other components of the wiki in the file system where this is more appropriate than insertion into the database, for example, site configuration files (,  (finally removed in 1.23)), image files (including deleted images, thumbnails and rendered math and SVG images, if applicable), skin customisations, extension files, etc.

The best method to back these up is to place them into an archive file, such as a  file, which can then be compressed if desired. On Windows, applications such as WinZip or 7-zip can be used if preferred.

For Linux variants, assuming the wiki is stored in /srv/www/htdocs/wiki tar zcvhf wikidata.tgz /srv/www/htdocs/wiki

It should be possible to backup the entire "wiki" folder in "htdocs" if using XAMPP.

Backup the content of the wiki (XML dump)
It is also a good idea to create an XML dump in addition to the database dump. XML dumps contain the content of the wiki (wiki pages with all their revisions), without the site-related data (they do not contain user accounts, image metadata, logs, etc).

XML dumps are less likely to cause problems with character encoding, as a means of transfering large amounts of content quickly, and are easily be used by third party tools, which makes XML dumps a good fallback should your main database dump become unusable.

To create an XML dump, use the command-line tool, located in the   directory of your MediaWiki installation. See dumpBackup2>Special:MyLanguage/Manual:dumpBackup.php|Manual:dumpBackup.php for more details.

You can also create an XML dump for a specific set of pages online, using Special:Export, although attempting to dump large quantities of pages through this interface will usually time out.

To import an XML dump into a wiki, use the command-line tool. For a small set of pages, you can also use the Special:Import page via your browser (by default, this is restricted to the sysop group). As an alternative to  and , you can use MWDumper, which is faster, but requires a Java runtime environment.

See import>Special:MyLanguage/Manual:Importing XML dumps|Manual:Importing XML dumps for more information.

Without shell access to the server
If you have no shell access, then use the WikiTeam Python script dumpgenerator.py from a DOS, Unix or Linux command-line.

Requires Python v2 (v3 doesn't yet work).

To get an XML, with edit histories, dump and a dump of all images plus their descriptions. Without extensions and LocalSettings.php configs.

Full instructions are at the WikiTeam [https://github.com/WikiTeam/wikiteam/wiki/Tutorial#I_have_no_shell_access_to_server tutorial].

See also Data dumps.

Scripts

 * script>Special:MyLanguage/Manual:Backing up a wiki/Duesentrieb's backup script|Unofficial backup script by User:Duesentrieb.


 * Unofficial backup script by Flominator; creates a backup of all files and the database, with optional backup rotation.


 * User:Darizotas/MediaWiki Backup Script for Windows - a script for backing up a Windows MediaWiki install. Note: Has no restore feature.


 * Unofficial web-based backup script, mw_tools, by Wanglong (allwiki.com); you can use it to back up your database, or use the backup files to recover the database, the operation is very easy.


 * [https://github.com/WikiTeam/wikiteam</> WikiTeam tools] - if you do not have server access (e.g. your wiki is in a free wikifarm), you can generate an XML dump and an image dump using WikiTeam tools (see [<tvar|backups>https://github.com/WikiTeam/wikiteam/wiki/Available-Backups</> some saved wikis])


 * Another [<tvar|url>https://github.com/samwilson/MediaWiki_Backup</> backup script] that: dumps DB, files, and XML; puts the site into read-only mode; timestamps backups; and reads the charset from LocalSettings. Script does not need to be modified for each site to be backed up. Does not (yet) rotate old backups. Usage: <tvar|code></>


 * Script to make periodical backups [<tvar|url>https://github.com/nischayn22/mw_backup</> mw_backup]. This script will make daily, weekly and monthly backups of your database and images directory when run as a daily cron job.