mediawiki迁移(含版本更新)

1 数据库备份

在原机器上直接输入下面的命令进行备份!
mysqldump -p DataMining2021 -u root > DataMining2021.sql

然后回车,提示你输入数据库登陆密码,输入完密码后回车,OK! 就把数据库备份到当前目录下了

问题是:目录大小明明有119M,但导出的.sql文件竟然只有40M

迁移过后,在新的空间同样用ssh对数据库进行恢复。首先创建数据库,再使用mysql命令恢复数据库:

(base) [root@localhost rsync]# mysql -uroot -p
Enter password: 
...
mysql> CREATE DATABASE DataMining2021 ;
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye
(base) [root@localhost rsync]# mysql -p DataMining2021 -u root < DataMining2021.sql

可以再/var/lib/mysql/看到文件夹的大小还原为107M

2 启动mediawiki

启动mediawiki容器并映射 /var/www/html 中所有文件夹。

docker run --name wiki \
	-v /var/www/html:/var/www/html \
	--link mysql:mysql \
	-p 8000:80 -d \
	mediawiki:stable

docker镜像会在文件夹下创建很多内容,将这些内容移动到一个文件夹wiki中,并在浏览器中打开ip:port/wiki进行设置,初始化测试用的wiki页面。(为更新迁移准备)

3 所有文件的备份

把备份的数据同步到新的空间:

cd /var/www/html
rsync --info=progress2 -a root@118.190.210.193:/var/www/html/ .

由于版本不同,不能复用原先的配置文件,仅把资源文件拷贝过去。以下参数改成具体的文件夹:

cp -r wiki nwiki
\cp -rf [p#1 参数名]/images/* nwiki/images/
\cp -rf [p#1 参数名]/extensions/* nwiki/extensions/
\cp -rf [p#1 参数名]/skins/* nwiki/skins/
mv [p#1 参数名] [p#1 参数名].bac
mv nwiki [p#1 参数名]
chmod 777 -R [p#1 参数名]
rm [p#1 参数名]/LocalSettings.php

4 配置

删除LocalSettings.php并重新生成(手动配置数据库),在网站上进行一系列设置,最后导出,并在LocalSettings.php添加:

...
    
$wgMinimalPasswordLength = 0;
## The URL path to static resources (images, scripts, etc.)
$wgResourceBasePath = $wgScriptPath;

## The relative URL path to the skins directory
$wgStylePath = "$wgScriptPath/skins";

$wgEnableUploads = true; # 启用上传

## The relative URL path to the logo.  Make sure you change this from the default,
## or else you'll overwrite your logo when you upgrade!
$wgLogos             = ["$wgStylePath/common/images/wiki.png"];
$wgLogo             = "$wgStylePath/common/images/wiki.png";

...


$wgShowSQLErrors=true;
$wgShowExceptionDetails = true;

# End of automatically generated settings.
# Add more configuration options below.
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'doc',
    'xls', 'pdf', 'ppt', 'tiff', 'bmp', 'docx', 'xlsx', 'pptx',
    'zip', 'jpg'
);

# Group permissions
$wgGroupPermissions['*']['edit'] = false;


# End of automatically generated settings.
# Add more configuration options below.

# 在新窗口打开
$wgExternalLinkTarget = '_blank';

$wgMaxUploadSize = 1024 * 1024 * 100;
$wgUploadSizeWarning = 1024 * 1024 * 100;

mediawiki复制

如果不需要在不同主机之间迁移,而仅是复制原有的服务到新的,只是更换一个路径,那么可以这么做:

  • cp -r DataMining2021 DataMining2022
  • rm DataMining2022/LocalSettings.php
  • 登陆网站重新配置,这个配置中数据库部分参考DataMining2021/LocalSettings.php

2d5fcefe22921016dddb29c51383a33

  • 用户名设置为root,密码设置为DataMining2022
  • 将生成的LocalSettings.php中仿造之前的setting增加一些配置(可以直接在以前的配置上修改,主要是DataMining2021改成DataMining2022,以及wgSecretKey, wgUpgradeKey)
  • 将LocalSettings.php上传到文件夹
  • 如果不想要之前版本文件夹中的一些图片和文件,就在相应的文件夹上删去(如rm -rf ./images/

整体配置文件如下,供参考:

<?php
# This file was automatically generated by the MediaWiki 1.35.2
# installer. If you make manual changes, please keep track in case you
# need to recreate them later.
#
# See includes/DefaultSettings.php for all configurable settings
# and their default values, but don't forget to make changes in _this_
# file, not there.
#
# Further documentation for configuration settings may be found at:
# https://www.mediawiki.org/wiki/Manual:Configuration_settings

# Protect against web entry
if ( !defined( 'MEDIAWIKI' ) ) {
        exit;
}

# Paul / Beihangg1121

## Uncomment this to disable output compression
# $wgDisableOutputCompression = true;

$wgSitename = "DataMining2022";

## The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
## For more information on customizing the URLs
## (like /w/index.php/Page_title to /wiki/Page_title) please see:
## https://www.mediawiki.org/wiki/Manual:Short_URL
$wgScriptPath = "/DataMining2022";

## The protocol and server name to use in fully-qualified URLs
$wgServer = "http://152.136.185.123:8000";


$wgMinimalPasswordLength = 0;
## The URL path to static resources (images, scripts, etc.)
$wgResourceBasePath = $wgScriptPath;
## The relative URL path to the skins directory
$wgStylePath = "$wgScriptPath/skins";
$wgEnableUploads = true; # 启用上传
## The relative URL path to the logo.  Make sure you change this from the default,
## or else you'll overwrite your logo when you upgrade!
$wgLogos             = ["$wgStylePath/common/images/wiki.png"];
$wgLogo             = "$wgStylePath/common/images/wiki.png";


## UPO means: this is also a user preference option

$wgEnableEmail = true;
$wgEnableUserEmail = true; # UPO

$wgEmergencyContact = "apache@🌻.invalid";
$wgPasswordSender = "apache@🌻.invalid";

$wgEnotifUserTalk = false; # UPO
$wgEnotifWatchlist = false; # UPO
$wgEmailAuthentication = true;

## Database settings
$wgDBtype = "mysql";
$wgDBserver = "152.136.185.123:9023";
$wgDBname = "DataMining2021";
$wgDBuser = "root";
$wgDBpassword = "Vis_2014";

# MySQL specific settings
$wgDBprefix = "";

# MySQL table options to use during installation or update
$wgDBTableOptions = "ENGINE=InnoDB, DEFAULT CHARSET=binary";

# Shared database table
# This has no effect unless $wgSharedDB is also set.
$wgSharedTables[] = "actor";

## Shared memory settings
$wgMainCacheType = CACHE_NONE;
$wgMemCachedServers = [];

## To enable image uploads, make sure the 'images' directory
## is writable, then set this to true:
$wgEnableUploads = false;
$wgUseImageMagick = true;
$wgImageMagickConvertCommand = "/usr/bin/convert";

# InstantCommons allows wiki to use images from https://commons.wikimedia.org
$wgUseInstantCommons = false;

# Periodically send a pingback to https://www.mediawiki.org/ with basic data
# about this MediaWiki instance. The Wikimedia Foundation shares this data
# with MediaWiki developers to help guide future development efforts.
$wgPingback = true;

## If you use ImageMagick (or any other shell command) on a
## Linux server, this will need to be set to the name of an
## available UTF-8 locale. This should ideally be set to an English
## language locale so that the behaviour of C library functions will
## be consistent with typical installations. Use $wgLanguageCode to
## localise the wiki.
$wgShellLocale = "C.UTF-8";

## Set $wgCacheDirectory to a writable directory on the web server
## to make your wiki go slightly faster. The directory should not
## be publicly accessible from the web.
#$wgCacheDirectory = "$IP/cache";

# Site language code, should be one of the list in ./languages/data/Names.php
$wgLanguageCode = "zh-cn";

$wgSecretKey = "535b3709abbf3ec3e102698ad04743a95e7b6081445786b7cb34342b20d0b8ae";

# Changing this will log out all existing sessions.
$wgAuthenticationTokenVersion = "1";

# Site upgrade key. Must be set to a string (default provided) to turn on the
# web installer while LocalSettings.php is in place
$wgUpgradeKey = "87f6579ada84b3a7";

## For attaching licensing metadata to pages, and displaying an
## appropriate copyright notice / icon. GNU Free Documentation
## License and Creative Commons licenses are supported so far.
$wgRightsPage = ""; # Set to the title of a wiki page that describes your license/copyright
$wgRightsUrl = "";
$wgRightsText = "";
$wgRightsIcon = "";

# Path to the GNU diff3 utility. Used for conflict resolution.
$wgDiff3 = "/usr/bin/diff3";

## Default skin: you can change the default skin. Use the internal symbolic
## names, ie 'vector', 'monobook':
$wgDefaultSkin = "vector";

# Enabled skins.
# The following skins were automatically enabled:
wfLoadSkin( 'MonoBook' );
wfLoadSkin( 'Timeless' );
wfLoadSkin( 'Vector' );


# End of automatically generated settings.
# Add more configuration options below.


$wgShowSQLErrors=true;
$wgShowExceptionDetails = true;

# End of automatically generated settings.
# Add more configuration options below.
$wgFileExtensions = array( 'png', 'gif', 'jpg', 'jpeg', 'doc',
    'xls', 'pdf', 'ppt', 'tiff', 'bmp', 'docx', 'xlsx', 'pptx',
    'zip', 'jpg'
);

# Group permissions
$wgGroupPermissions['*']['edit'] = false;
$wgEnableUploads = true; # 启用上传

# End of automatically generated settings.
# Add more configuration options below.

# 在新窗口打开
$wgExternalLinkTarget = '_blank';

# wfLoadExtension('DeleteBatch');

$wgMaxUploadSize = 1024 * 1024 * 100;
$wgUploadSizeWarning = 1024 * 1024 * 100;