Руководство: Восстановление вики-страницы из резервной копии

From mediawiki.org
This page is a translated version of the page Manual:Restoring a wiki from backup and the translation is 8% complete.

Следует регулярно создавать резервные копии своей вики, даже если вам никогда не понадобится ее восстанавливать: резервные копии обеспечивают душевное спокойствие. Однако резервная копия бесполезна, если вы не можете восстановить, и практика восстановления резервной копии предотвращает последующие страдания. Отсюда и эти инструкции.

Версии и обновления

Инструкции на этой странице должны применяться более или менее равномерно к любой существующей версии MediaWiki. You can restore the database to a more recent version of MediaWiki, but be sure to run the update script. Restoring a database backup of a newer version into an older version of the software is not supported.

File transfer

Unless you have direct access to the server hosting the wiki, (and even then) you will have to choose a method for transferring files:


  1. Re-create the database, user and permissions
  2. Import the database backup
  3. Import the MediaWiki files
  4. Check the configuration file
  5. Test

Re-create the database, user and permissions

On the server on which you are restoring MediaWiki, ensure you have

  1. a correctly-working instance of MySQL
  2. a MySQL user with appropriate permissions, if you can't use MySQL user root

If you are restoring from backup due to database corruption, consider reinstalling MySQL!

Once MySQL is working properly, create a new MySQL database and grant your user account permissions on the database listed below.

You may need to consult the MySQL documentation, your hosting provider's control panel documentation, or the documentation of any other utilities you are using for information on how to do this.

From the MySQL prompt as MySQL user root you can:

CREATE USER wikidb_user IDENTIFIED BY 'wikidb_userpassword';

USE wikidb;
It doesn't matter if the database doesn't have the same name; indeed, in a commercial hosting environment, where database names are usually prefixed with a hosting account username, a different database name is almost guaranteed. In addition, the username can differ, as can that user's password. You will have to adjust the LocalSettings.php file on the new location accordingly.

Import the database backup

See also Manual:Importing XML dumps

Next, import your database backup.

This will create the tables in the database and populate them with data.

Importing takes a variable amount of time, depending upon the number of pages, users, edits, etc. in your wiki.


From the command line using mysqladmin

If a database exists and you want to entirely replace it from the backup. To destroy the database:

mysqladmin -u wikidb_user -p drop wikidb

Substituting as appropriate for wikidb_user and wikidb. The -p parameter will prompt you for the password.

Then to create a new database:

mysqladmin -u wikidb_user -p create wikidb

For example after backing up with mysqldump:

# Don't do this now: This is how you might have created a backup earlier.
mysqldump --default-character-set=binary --user=wikidb_user --password=wikidb_userpassword wikidb > dump_of_wikidb.sql
# The wikidatabase wikidb from which you backed up may have a different name
# than the wikidatabase wikidb you've created above. Of course wikidb_user and
# wikidb_userpassword may be different as well.

Make sure to specify the correct character set or the restore may fail, check LocalSettings.php to find out which character set it is.

To import dump_of_wikidb.sql from the command line you simply do:

mysql -u wikidb_user -p wikidb < dump_of_wikidb.sql

and afterwards if required do:

php wikifolder/maintenance/update.php
# Most people name their wikifolder simply "w", making this pathname 
# something like "htdocs/w/maintenance/update.php"
After using dump, you shouldn't use mysqlimport to restore your wikidatabase, you should use sql. Because mysqlimport requires the data to be loaded in some delimited text format, eg. CSV, whereas the output of mysqldump is a sequence of SQL statements.
If not copying the old LocalSettings.php to a new install ensure the database prefix is set to the prior installation's in the new installation before running php update.php

See also Executing SQL Statements from a Text File

If your site is slow after importing a database dump, you may need to rebuild indexes. See After importing sql files indexes in place, but not actually indexed

With the browser for phpMyAdmin

Open the browser to your phpMyAdmin, login, choose the wiki database. (Check LocalSettings.php if you're not sure). Follow the instructions in the phpMyAdmin documentation.

From an XML dump

To import an XML dump into a wiki, use the command-line tool importDump.php . Do:

php wikifolder/maintenance/importDump.php --dbpass wikidb_userpassword --quiet --wiki wikidb path-to-dumpfile/dumpfile.xml
php wikifolder/maintenance/rebuildrecentchanges.php

Substitute wikidb_userpassword, wikidb and path-to-dumpfile/dumpfile.xml as appropriate.

Afterwards use ImportImages.php to import the images:

php wikifolder/maintenance/importImages.php wikifolder_backup/images

Import the MediaWiki files

See also Manual:importImages.php

Next, restore your backup of the MediaWiki filesystem: this is the final "large" step in the restore process.

  • If you followed the backup manual instructions, and backed up the entire directory, this will include the images and extensions directories, plus custom skins, etc. and the configuration file.
  • If you backed up only portions of the directory, e.g. images, extensions, etc. then you will need to first upload/copy a fresh install of the MediaWiki files, then transfer the backed-up directories and files into the correct locations in the new filesystem.
To wipe and restore the wiki file system

Remember to also restore the file system components of the wiki that might be required, eg. images, logo, and extensions. Especially to edit LocalSettings.php to check everything is correct. A sequence of Linux commands to wipe and restore the wiki file system could look like this:

wget http://download.wikimedia.org/mediawiki/1.41/mediawiki-1.41.1.tar.gz
tar -xvzf mediawiki-1.41.1.tar.gz
rm mediawiki-1.41.1.tar.gz
rm -fR wikifolder/
mv mediawiki-1.41.1 wikifolder
rm -fR wikifolder/extensions/
cp -R wikifolder_backup/extensions wikifolder/extensions

Open the wiki from the browser and click on the Set up the wiki first link. See Manual:Настройка скрипта for details. If needed, you can run the command-line installer php wikifolder/maintenance/install.php. After this is done edit LocalSettings.php to suit the fresh install, restoring lines for extensions, etc. Restore from backup any other files, such as a custom logo and favicon to the correct paths.

If you've not installed as a root Linux/Unix user and the images and thumbnails don't work, you'll need to fix the owner or permissions recursively on the folder that has the uploaded images, usually in wikifolder/images.


  • If following the latter process, ensure that your "fresh install" consists of the same version of MediaWiki as the old one did
  • Check that the upload directory (e.g. images in version 13) has the correct permissions set if using uploads; it needs to be writable by the web server.
  • Make sure any extension directories have the correct permissions as well (e.g. if linux: chmod -R o=rx extensions or chmod -R o=rx includes)
  • The best method to use when manually transferring a wiki from a windows platform to a Linux platform involves:
    1. Manually installing MediaWiki on the Linux platform from a tar file as outlined here: Manual Install of Wiki (i.e. try not to use install from a automated package)
    2. Replacing the newly installed MediaWiki folder (e.g. /var/www/mediawiki...) on your Linux machine with the MediaWiki base folder from your windows machine
    3. Updating your Linux machine's MySQL Database (e.g. wikidb) with the wiki database from your windows machine (i.e. use the backup and restore features of mysql as outlined above)
  • After importing a wiki database, even if the database can work, some minor problems may arise:
    1. Searchindex may need to be repaired: In phpMyAdmin, enter REPAIR TABLE wikidb.searchindex; for rebuilding the search index. wikidb is your database's name.
    2. The collation of some rows may be changed. Cross check it with the original database.

Check the configuration file

The final task involves verification of, and possibly modifying, the LocalSettings.php file.

  • If you are restoring onto the same server from which you backed up, you probably need not change anything.
  • If you are restoring onto a new server (i.e., if you are moving or duplicating the MediaWiki), certain entries will almost undoubtedly require changing, and you may need to change the database connection information as well.

Check the following configuration options:

Configuration option Action required Default/Example
$IP Needs to be correct for the paths on the new server

(Usually remains the same, so change is not required)

 if( defined( 'MW_INSTALL_PATH' ) ) {
 } else {
 	$IP = dirname( __FILE__ );
$wgScriptPath Needs to be correct for the path on the new server

$wgScriptPath = "wikifolder";
$wgScriptPath = "/w";

$wgArticlePath Needs to be correct for the path on the new server

$wgArticlePath = "$wgScriptPath/$1";
$wgArticlePath = "/wiki/$1";

$wgDBserver Check the database server name is correct

$wgDBserver = "localhost";

$wgDBname This might have changed in a shared hosting environment

$wgDBname = "wikidb";

$wgDBuser This might have changed in a shared hosting environment

$wgDBuser = "wikidb_user";

$wgDBpassword Check this is correct for the new user

$wgDBpassword = "wikidb_userpassword";

You might also need to check the paths to diff3, ImageMagick, etc.


At this point, attempt to access the wiki on the new server and use it. Log in as a sysop and a regular user and check that viewing, creating and editing pages and uploading files still works. You will need to fix any problems reported either by PHP or MediaWiki itself.

Frequent problems

After your move you might see PHP warnings stating that certain files could not be accessed. This is most likely caused by phabricator:T37472: The column md_deps in the module-deps table contains absolute file paths, which are used to locate the images and LESS files that CSS depends on. These paths will break when the wiki is e.g. moved to another folder or to another server.

Until this bug is solved, you can use this workaround to manually fix wrong entries in the module_deps table:

SET @old='wiki.old-domain.org';
SET @new='wiki.new-domain.org';

UPDATE `module_deps` SET `md_deps` = REPLACE( `md_deps`, @old, @new );

This can be used to update wrong path segments and to fix the error.

См. также