매뉴얼:위키를 백업하는 법

From mediawiki.org
This page is a translated version of the page Manual:Backing up a wiki and the translation is 10% complete.
Outdated translations are marked like this.

귀하의 위키 데이터를 정기적으로 백업하는 것은 매우 중요합니다. 이 페이지에서는 일반적인 미디어위키 기반 위키의 백업 과정에 대한 개괄을 제공합니다. 당신은 아마도 위키의 크기와 당신의 개인적인 필요성에 맞춰서 자신의 백업 스크립트를 고안하거나 일정을 계획하고 싶을 것입니다.

Help:Export 은 당신의 위키에 있는 모든 페이지를 저장하기 위한 빠르고 쉬운 방식입니다.


위키미디어는 중요한 데이터를 두 곳에 저장합니다.

페이지 및 내용, 사용자 데이터 및 환경 설정, 메타데이터, 검색 색인 등의 내용
파일 시스템
소프트웨어 설정 파일, 맞춤 스킨, 확장기능, 이미지 (삭제된 이미지 포함) 등의 내용

백업하기 전에 위키를 읽기전용으로 만드는 것을 고려하십시오 - $wgReadOnly 를 보십시오. 이를 통해 당신의 모든 백업 파츠들이 일관성을 유지할 수 있습니다. (그렇더라도 일부 당신이 설치한 확장기능들이 데이터를 쓸(write) 수는 있습니다.)

파일 전송

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

  • Non-private data you can simply publish on archive.org and/or in a dumps/ directory of your webserver.
  • SCP (or WinSCP), SFTP/FTP or any other transfer protocol you choose.
  • The hosting company might provide a file manager interface via a web browser; check with your provider.


Most of the critical data in the wiki is stored in the database. If your wiki is currently offline, its database can be backed up by simply copying the database file.

When using the default MySQL or MariaDB 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.



See the package on Debian:

$ apt show automysqlbackup
Description: automysqlbackup creates backup every day, week and month for all of your MySQL database, to a configured folder. There's nothing to do but to install this package, and you'll rest assured that you have a way to go back in the history of your database.

패키지 설치:

# apt install automysqlbackup

All your databases will be saved in /var/lib/automysqlbackup/:

$ find /var/lib/automysqlbackup/

Manual backup:

# automysqlbackup

Restore a database:

gunzip < /var/lib/automysqlbackup/weekly/my_wiki/my_wiki_week.18.2016-05-07_15h32m.sql.gz|mysql -uUSER -pPASSWORD my_wiki

For other distributions, see on Sourceforge.

Mysqldump from the command line

The most convenient way to create a dump file of the database you want to back up is to use the standard MySQL dump tool mysqldump from the command line. Be sure to get the parameters right or you may have difficulty restoring the database. Depending on database size, mysqldump could take a considerable amount of time.

First insert the following line into LocalSettings.php

$wgReadOnly = 'Dumping Database, Access will be restored shortly';

this can be removed as soon as the dump is completed.

Example of the command to run on the Linux/UNIX shell:

mysqldump -h hostname -u userid -p --default-character-set=whatever dbname > backup.sql

Substituting hostname, userid, whatever, and dbname as appropriate. All four may be found in your LocalSettings.php (LSP) file. hostname may be found under $wgDBserver ; by default it is localhost. userid may be found under $wgDBuser , whatever may be found under $wgDBTableOptions , where it is listed after DEFAULT CHARSET=. If whatever is not specified mysqldump will likely use the default of utf8, or if using an older version of MySQL, latin1. While dbname may be found under $wgDBname . After running this line from the command line mysqldump will prompt for the server password (which may be found under Manual:$wgDBpassword in LSP).

See mysqldump for a full list of command line parameters.

The output from mysqldump can instead be piped to gzip, for a smaller output file, as follows

mysqldump -h hostname -u userid -p dbname | gzip > backup.sql.gz

Some newer versions of MySQL might show an error about tablespaces and PROCESS privilege. MediaWiki does not use tablespaces. The solution is to add the --no-tablespaces option to the command:

mysqldump --no-tablespaces -h hostname -u userid -p dbname | gzip > backup.sql.gz

A similar mysqldump command can be used to produce XML output instead, by including the --xml parameter.

mysqldump -h hostname -u userid -p --xml dbname > backup.xml

and to compress the file with a pipe to gzip

mysqldump -h hostname -u userid -p --xml dbname | gzip > backup.xml.gz

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

Cron 으로 mysqldump 실행하기

Cron is the time-based job scheduler in Unix-like computer operating systems. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates.

A sample command that you may run from a crontab may look like this:

nice -n 19 mysqldump -u $USER --password=$PASSWORD $DATABASE -c | nice -n 19 gzip -9 > ~/backup/wiki-$DATABASE-$(date '+%Y%m%d').sql.gz

The nice -n 19 lowers the priority of the process.

Use valid values for $USER, $PASSWORD, and $DATABASE. This will write a backup file with the weekday in the filename so you would have a rolling set of backups. If you want to save the files and extensions as well, you might want to use this one.

경고 경고: Do not attempt to back up your MediaWiki database using mysqlhotcopy. The table format used by MediaWiki cannot be backed up with this tool, and it will fail silently!

If you want to add this task in Cron through Cpanel then you must escape the character "%"

/usr/bin/mysqldump -u $USER --password=$PASSWORD $DATABASE -c | /bin/gzip > ~/backup/wiki-$DATABASE-$(date '+\%Y\%m\%d').sql.gz

or you will get an error:

/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file


Some of the tables dumped have different degrees of temporariness. So to save disk space (beyond just gziping), although those tables need to be present in a proper dump, their data does not. However, under certain circumstances the disadvantage of having to rebuild all this data may outweigh saving disk space (for example, on a large wiki where restoration speed is paramount).

See mailing list thread mysql5 binary schema about the topic.

Latin-1 to UTF-8 conversion

See the relevant section of the upgrading page for information about this process. Also see the talk page for more information about working with character sets in general.


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

pg_dump mywiki > mywikidump.sql

will dump the mywiki 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


If your wiki is currently offline, its database can be backed up by simply copying the database file. Otherwise, you should use a maintenance script: php maintenance/SqliteMaintenance.php --backup-to <backup file name>, which will make sure that operation is atomic and there are no inconsistencies. If your database is not really huge and server is not under heavy load, users editing the wiki will notice nothing but a short lag. Users who are just reading will not notice anything in any case.


Turn your wiki to read only by adding $wgReadOnly = 'Site Maintenance'; to LocalSettings.php.

Find the wiki database in LocalSettings.php. Here is an example of what this looks like in LocalSettings.php:

## Database settings
$wgDBtype           = "mysql";
$wgDBserver         = "localhost";
$wgDBname           = "sashtmax_mw19999";
$wgDBuser           = "sashtmax_mw19999";
$wgDBpassword       = "S7[88p]jJJ";
  1. Open the browser to your phpadmin link, login, choose the wiki database.
  2. 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.
  3. Select zipped.
  4. Click on GO and save the backup file.[1]
  5. Remove $wgReadOnly = 'Site Maintenance'; from LocalSettings.php

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

External links

HeidiSQL (alternative to phpMyAdmin)

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.

The most important of these are:

  • LocalSettings.php
  • uploaded files in the images/ directory (including deleted files, thumbnails, and rendered math and SVG images, if applicable).

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

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.

Configuration files

LocalSettings.php is the most important of these, but a wiki might also have things like .htaccess or other web server configuration files that should be backed up.

Uploaded files

Files uploaded to the wiki are by default put into the images/ directory, separated into subdirectories such as images/8/8f. There are also other directories such as images/archive/ and images/deleted/. These should all be backed up.

The images/thumb/ can be backed up along with everything else, but can optionally be excluded in order to save backup space. This directory stores the derived thumbnails of images and other files; generally multiple thumbnails per wiki file. After restoring from backup, these thumbnails will be recreated as required (although depending on $wgGenerateThumbnailOnParse this may need to be a manual process).

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).[2]

XML dumps are less likely to cause problems with character encoding, as a means of transferring large amounts of content quickly, and can 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 dumpBackup.php , located in the maintenance directory of your MediaWiki installation. See 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 importDump.php . 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).

See Manual:Importing XML dumps for more information.

Without shell access to the server

If you have no shell access, use the MediaWiki Client Tools' MediaWiki Scraper dumpgenerator script, a Python 3.x port of the WikiTeam Python 2.7 dumpgenerator.py script. It is run from the command-line in a terminal.

The XML dump can include full or only most recent page history. The images dump will contain all file types with associated descriptions. The siteinfo.json and SpecialVersion.html files will contain information about wiki features such as the installed extensions and skins. User account information won't be preserved.

Full instructions are at the Mediawiki Client Tools' Mediawiki Scraper GitHub repository.

See also Meta:Data dumps.


경고 경고: Use these at your own risk. Check your wiki's LocalSettings.php for the correct character set to use, as you may need to edit the script to suit.

Shell script, last updated 2012.

  • Another backup script that: dumps DB, files (just pictures by default, option to include all files in installation), 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: backup.sh -d backup/directory -w installation/directory. Also provides a script to restore a backup restore.sh -a backup/directory/dated_archive.tar.gz -w installation/directory. Shell script, last updated 2013.

Shell script, last updated 2015.

Shell script, last updated 2016.

  • Script to make periodical backups mw_backup. This script will make daily, weekly and monthly backups of your database and images directory when run as a daily cron job.

PHP script, last updated 2017.

  • Another unofficial MediaWiki backup script for Windows by Lanthanis that: exports the pages of specified namespaces as an XML file; dumps specified database tables; and adds further specified folders and files to a ZIP backup file.

Can be used with Windows task scheduler. Last updated 2019.

  • 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 dumpgenerator from WikiTeam tools, (Python 2). See some saved wikis.

Python 2 script.

  • Mediawiki Scraper - 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 dumpgenerator from Mediawiki Client Tools, Python 3 script, last update 2023.


같이 보기


  1. Manual talk:Backing up a wiki#Ubuntu 10.10 - Step by Step Instructions
  2. XML dumps are independent of the database structure, and can be imported into future (and even past) versions of MediaWiki.