Manual:Restoring a wiki from backup

From MediaWiki.org
Jump to: navigation, search

One should backup one's wiki regularly, even if one never needs to restore it: backups provide peace of mind. However, a backup is useless if one cannot restore, and practice restoring a backup prevents later anguish. Hence, these instructions.

Versions and upgrading[edit | edit source]

The instructions on this page should apply more or less evenly to any given version of MediaWiki. However, avoid upgrading MediaWiki or its database schema prior to restoring! Particularly, avoid restoring a database backup from an older version of the software into a newer version; this will not work.

File transfer[edit | edit source]

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

Overview[edit | edit source]

  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[edit | edit source]

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

  1. a correctly-working instance of MySQL
  2. a user with appropriate permissions

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. SELECT, INSERT, UPDATE and DELETE permissions should suffice. 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 root you can:

CREATE DATABASE wikidb ;

CREATE USER wikiuser;

USE wikidb;

GRANT SELECT ON wikidb.* TO wikiuser;

GRANT UPDATE ON wikidb.* TO wikiuser;

GRANT INSERT ON wikidb.* TO wikiuser;

GRANT DELETE ON wikidb.* TO wikiuser;


Note: 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[edit | edit source]

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.

Methods[edit | edit source]

From the command line using mysql[edit | edit source]

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

mysqladmin -u [userid] -p drop [wikidbname]

Substituting as apropriate for userid and wikidbname. the -p parameter will prompt you for the password.

Then to create a new database:

mysqladmin -u [userid] -p create [wikidbname]

For example after backing up with mysqldump, eg.

# don't do this now: this is how you might have created a backup earlier
mysqldump --default-character-set=binary --user=foobar --password=barbaz  wikidb > dbdump.sql

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

Note: After using mysqldump, you can't just use mysqlimport. 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.

To import dbdump.sql from the command line do:

mysql -u [userid] -p [databasename] < dbdump.sql

and afterwards, if required do:

php wiki_folder/maintenance/update.php
To wipe and restore the wiki file system[edit | edit source]

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.22/mediawiki-1.22.5.tar.gz
tar -xpzf mediawiki-1.22.5.tar.gz
rm mediawiki-1.22.5.tar.gz
rm -fR wiki_folder/
mv mediawiki-1.22.5 wiki_folder
rm -fR wiki_folder/extensions/
cp -R backup/extensions wiki_folder/extensions

Open the wiki from the browser and click on the Set up the wiki first link. See Manual:Config script for details. If needed, you can run the command-line installer php wiki_folder/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 user and the images and thumbnails don't work, you'll need to

chmod 777 wiki_folder/images

this creates a security risk, so add Options -Indexes to the wiki folder's .htaccess file, to prevent folder browsing.

See also Executing SQL Statements from a Text File

With the browser for phpMyAdmin[edit | edit source]

Open the browser to your phpadmin link, login, choose the wiki database. (Check LocalSettings.php if you're not sure). Select Structure, localhost, Your_Table. Select CheckAll. From the drop down select Drop, then Ok to wipe the old table. Click on Import, select Browse, pick your uncompressed plain text SQL file and import it. Press Go.[1]

Remember to also restore file system components of the wiki that might be required, eg. images, logo, and extensions, (see above under mysql).

Depending on timeout settings and the size of the SQL file, it may take multiple attempts to import everything. Failure to complete the import may leave the database in an inconsistent state, e.g. with missing revisions.

External links[edit | edit source]

From an xml dump[edit | edit source]

Main article: Manual:Importing XML dumps

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

php wiki_folder/maintenance/importDump.php --dbpasspassword --quiet wikidbname path_to/dumpfile.xml
php rebuildrecentchanges.php

Substituting password wikidbname path_to/dumpfile.xml as apropriate.

Afterwards use ImportImages.php to import the images:

php importImages.php ../path_to/images

Import the MediaWiki files[edit | edit source]

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.

Notes[edit | edit source]

  • 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 wikimedia 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 wikimedia folder (e.g. /var/www/mediawiki...) on your Linux machine with the wikimedia 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[edit | edit source]

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)

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

$wgScriptPath = "/wiki";

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

# $wgArticlePath = "$wgScript/$1";

$wgDBserver Check the database server name is correct Example:

$wgDBserver = "localhost";

$wgDBname This might have changed in a shared hosting environment Example:

$wgDBname = "igot_mwiki";

$wgDBuser This might have changed in a shared hosting environment Example:

$wgDBuser = "igot_mwiki";

$wgDBpassword Check this is correct for the new user Example:

$wgDBpassword = "passa";

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

Test[edit | edit source]

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.

See Also[edit | edit source]

External links[edit | edit source]

References[edit | edit source]

Language: English