Manual:ウィキをバックアップから復元する

From mediawiki.org
This page is a translated version of the page Manual:Restoring a wiki from backup and the translation is 39% complete.
Outdated translations are marked like this.

例え復元する必要がないウィキであっても、定期的にウィキのバックアップを実施すべきです。バックアップは安心を与えてくれます。 ところが、バックアップは復元できないと役に立ちません。バックアップを復元すれば後の面倒な作業をしなくて済むのです。 以下はその方法についての説明です。

バージョンとアップグレード

このページにある説明は概ねどのバージョンの MediaWiki にも通用する内容となっているでしょう。 データベースはより新しいバージョンの MediaWiki に復元できますが、更新スクリプトを忘れず実行するようにしてください。 新しいバージョンのデータベースを古いバージョンのソフトウェアに復元する操作はサポートしていません。

ファイル転送

ウィキを置いているサーバへ直接アクセスできない場合、ファイルを転送する方法を選ぶ必要があります。

  • putty または WinSCP を使って安全にコピーする
  • SSH ファイル転送プロトコル(SFTP)
  • FTP クライアントを使う
  • ホスティング会社がウェブブラウザを使ったファイル管理インタフェースを提供しているかもしれません。提供会社から提供されている情報を確認してください。
  • この他の手段は、これらの手法を記したファイル転送プロトコル一覧に記載されています。

概要

  1. データベース、ユーザ、アクセス権限の再構築
  2. データベースのバックアップのインポート
  3. MediaWikiファイルのインポート
  4. 設定ファイルの確認
  5. テスト

データベース、ユーザ、アクセス権限の再構築

サーバにMediaWikiを復元するとき、以下の環境が満たされていることを確認してください。

  1. 正常に動作するMySQLデータベースサーバがあること
  2. あなたがMySQLのrootユーザを利用できない場合、必要な権限を持ったMySQLユーザを利用できること

データベースが壊れたためにバックアップから復元しようとしているなら、MySQLの再インストールを検討してください。MySQLが正常動作しているなら、新たなMySQLデータベースをつくり、あなたのユーザがアクセスできるよう下記のデータベースで権限を付与してください。どうやってそれを行うのかについては、[$mysql-doc/ MySQL文書]、あなたのサーバを提供するサービスプロバイダの設定パネルの文書、あるいはその他のあなたが使っているユーティリティに関する文書を調べる必要があるかもしれません。MySQLのrootユーザであれば、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 DATABASE wikidb;
CREATE USER wikidb_user IDENTIFIED BY 'wikidb_userpassword';

USE wikidb;
GRANT SELECT, UPDATE, INSERT, DELETE, ALTER, CREATE, INDEX, DROP, LOCK TABLES, USAGE ON wikidb.* TO wikidb_user;
データベースの名前は上記事例と同じでなくても構いません。実際、商用ホスティング環境ではホスティングアカウント名の接頭辞がつくことがよくあり、ほとんどは別の名前のデータベースに対して権限が与えられています。さらに、ユーザ名やパスワードも別の値を使って結構です。また $ls を新たな別の場所に置いた場合は、それに合うよう設定を調整してください。 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.

データベースのバックアップのインポート

See also Manual:Importing XML dumps

次にデータベースのバックアップを復元します。この操作によりデータベース内にテーブルが作成され、データも復元されます。取り込みにはしばらく時間がかかりますが、所要時間はウィキ内のページ数、ユーザ数、版の数に依存します。

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.

方法

mysqladminを使ってコマンドラインから実行する

データベースが既に存在しバックアップと完全に入れ替える場合は、既存のデータベースを削除します。

mysqladmin -u wikidb_user -p drop wikidb

wikidb_userwikidb はしかるべき値に置き換えてください。$p パラメータをつけるとパスワード入力を促すプロンプトが出ます。 The -p parameter will prompt you for the password.

次に新たなデータベースをつくります。

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.

正しい文字セットを指定してください。そうしないと復元に失敗します。 LocalSettings.phpを見て指定するべき文字セットを確認してください。

コマンドラインから dump_of_wikidb.sql を取り込む場合、必要となるのは以下のコマンドだけです。

mysql -u wikidb_user -p wikidb < dump_of_wikidb.sql

その後、必要があれば以下の操作も行ってください:

php wikifolder/maintenance/update.php
# Most people name their wikifolder simply "w", making this pathname 
# something like "htdocs/w/maintenance/update.php"
dumpを使用した後は、mysqlimportを使用してウィキデータベースを復元しないでください。sqlを使用してください。$mysqlimp2はデータを区切られたテキスト形式で読み込む必要があるためです。$csvですが、$dump2の出力は一連の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.
古いLocalSettings.phpを新しいインストールにコピーしない場合は、$prefixを実行する前に、データベースの接頭辞が新しいインストールで以前のインストールに設定されていることを確認してください

関連項目 テキストファイルからのSQL文の実行

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.

XMLダンプからの復元

メイン記事: Manual:XMLダンプの取り込み

XML ダンプをウィキに取り込むには、コマンドライン ツール importDump.php を使用して以下の操作を行ってください:

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

MediaWikiファイルのインポート

See also Manual:importImages.php

次にMediaWikiファイルシステムのバックアップを復元します。これが復元処理の「主要な」ステップとしては最後になります。

  • バックアップマニュアルに書かれた指示にしたがい、ディレクトリ全体をバックアップしていれば、images と extensions のディレクトリがバックアップに含まれているでしょう。また独自に導入した外装や設定もあるかもしれません。
  • imagesやextensionsなどディレクトリの一部分だけをバックアップした場合、まずMediaWikiの新規インストールファイル群をアップロードするかまたはどこかからコピーしてくる必要があります。その後、バックアップしたディレクトリやファイルを新たなファイルシステムの正しい場所に復元します。

ウィキのファイルシステムを完全に復元するには

ウィキに必要となるimages、logo、extensions. などのサブディレクトリも復元することを忘れないようにしてください。特にLocalSettings.phpの内容がすべて正しいことを確認し、必要があれば修正しください。Linux系環境では、以下のようなコマンド操作により既存内容を一旦すべて消去してからウィキのファイルシステムを復元することができます。 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.0.tar.gz
tar -xvzf mediawiki-1.41.0.tar.gz
rm mediawiki-1.41.0.tar.gz
rm -fR wikifolder/
mv mediawiki-1.41.0 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. 詳細は Manual:構成スクリプト を参照してください。 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.

設定ファイルの確認

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 既定値/例
$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' ) ) {
 	$IP = 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.

よくある問題

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.

関連項目

脚注