Manual:Backing up a wiki/ru

Регулярное выполнение резервного копирования является обязательным для всех систем. эта статья расскажет о том как выполняется резервное копирование для типовой MediaWiki системы.

Общие сведения
MediaWiki хранит данные в двух основных хранилищах:
 * База данных : Страницы и их содержимое, пользователи и их свойства, метаданные, индекс поиска и пр.
 * Файловая система : Файлы конфигурации, файлы тем, расширения, изображения (удаленные изображения).

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 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.

База данных
Большинство критических данных wiki хранится в базе данных, что, по сути, делает ее критическим компонентом вашей системы. Выполнять резерные копии БД можно различными инструментами.

Mysqldump from the command line
MySQL dump tool является приложением коммандной строки и предназначено для создания файлов "дампов" для базы данных.

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 --password --default-character-set=whatever dbname > backup.sql Substituting hostname, userid, character-set, and dbname as appropriate. mysqldump will prompt for the password. If no character set is specified, mysqldump x.x.x uses utf8, and earlier versions used latin1. Your wiki's database might be using binary. Check in the LocalSettings.php file to find out which (usually under $wgDBTableOptions DEFAULT CHARSET). Otherwise mysql might dump according to the server's file system and not the wiki's. The dbname can also be found in LocalSettings.php under $wgDBname.

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 --password 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 --password --xml dbname > backup.xml and to compress the file with a pipe to gzip mysqldump -h hostname -u userid --password --xml dbname | gzip > backup.xml.gz

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

Running mysqldump with Cron
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.

Пример команды которую вы можете запустить через crontab выглядит так  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  lowers the priority of the process.

Установите правильные значения для переменных $USER, $PASSWORD, $DATABASE. будет создан файл ежедневной копии базы данных. если вы сохраняете файлы и расширения таким образом то вы можете использовать метод предложенный здесь.

Если Вы хотите добавить задание сохранения базы в планировщик Cron через Cpanel, то вы должны экранировать символ "%" /usr/bin/mysqldump -u $USER --password=$PASSWORD $DATABASE -c | /bin/gzip > ~/backup/wiki-$DATABASE-$(date '+\%Y\%m\%d').sql.gz

В противном случае, Вы получите ошибку: /bin/sh: -c: line 0: unexpected EOF while looking for matching `'' /bin/sh: -c: line 1: syntax error: unexpected end of file

Таблицы
Under close examination one finds that some of the tables dumped have various 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 the saving in disk space (for example, on a large wiki where restoration speed is paramount).

Обратитесь в список рассылки - раздел по данному вопросу.

Кодировка
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.

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
HeidiSQL is similar to phpMyAdmin, but without any restrictions of phpMyAdmin's free version.

Файловая система
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.

Лучшим методом для сохранения этих данных является их сжатие в архив, например .tar файл. На Windows системах можно использовать Winzip или 7-zip.

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 Manual:dumpBackup.php for more details.

Если при попытке использования dumpBackup.php возникают проблемы обратитесь в раздел AdminSettings.php для исправления ошибки.

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 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. To run the script see the WikiTeam tutorial.

See also Data dumps.

Скрипты

 * Unofficial backup script by User:Duesentrieb.


 * неофициальный скрипт резервного копирования Flominator: User:Flominator/Backup MW; создает резервную копию всех файлов и базы данных с возможной ротацией резервных копий.


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


 * неофициальный скрипт резервного копирования с веб интерфейсом mw_tools от Wanglong (allwiki.com); вы можете использовать его как для бэкапа вашей базы данных так и для восстановления ее.


 * 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 some saved wikis)


 * Fullsitebackup


 * Another 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:


 * 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.