Skip to content

Instantly share code, notes, and snippets.

@frafra
Last active November 10, 2019 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frafra/2df3a9b13ddb270d9764fb43854034f5 to your computer and use it in GitHub Desktop.
Save frafra/2df3a9b13ddb270d9764fb43854034f5 to your computer and use it in GitHub Desktop.
Restore MediaWiki dump (example)
#!/bin/bash -ex
# https://dumps.wikimedia.org/backup-index.html
dump="https://dumps.wikimedia.org/nowiktionary/20191101/nowiktionary-20191101-pages-articles-multistream.xml.bz2"
# https://www.mediawiki.org/wiki/Extension:Scribunto
scribunto="https://extdist.wmflabs.org/dist/extensions/Scribunto-REL1_33-8328acb.tar.gz"
pod="wiktionary"
mysql=$(podman volume create)
cleanup() {
podman pod stop $pod
podman pod rm $pod || podman pod rm -f $pod
podman volume rm $mysql
}
#trap cleanup 0
mkdir -p shared
cd $_
if [ ! -f dump.xml ]; then
curl $dump | bzip2 -d > dump.xml
fi
if [ ! -f scribunto.tar ]; then
curl $scribunto | gzip -d > scribunto.tar
fi
cd -
podman pod exists $pod ||
podman pod create --name $pod -p 8080:80
mediawiki=$(podman run \
--rm -d --pod $pod \
mediawiki)
mariadb=$(podman run \
--rm -d --pod $pod \
-e MYSQL_ALLOW_EMPTY_PASSWORD=true \
--healthcheck-command 'mysql -h 127.0.0.1' \
-v $mysql:/var/lib/mysql \
mariadb)
while [ $(podman healthcheck run $mariadb) != "healthy" ]; do
sleep 10;
done
podman exec $mediawiki php maintenance/install.php \
--dbserver="127.0.0.1" --dbuser=root \
--server="http://127.0.0.1:8080" \
--scriptpath="" \
--lang=nb \
--pass=admin $pod "Admin"
# https://www.mediawiki.org/wiki/Extension:Scribunto
# https://phabricator.wikimedia.org/T159401
podman cp --extract shared/scribunto.tar $mediawiki:/var/www/html/extensions/
podman exec $mediawiki sh -c "cat << \EOF >> LocalSettings.php
wfLoadExtension( 'Scribunto' );
\$wgScribuntoDefaultEngine = 'luastandalone';
EOF"
podman cp shared/dump.xml $mediawiki:/var/www/html
podman exec $mediawiki sh -c "php maintenance/importDump.php --conf LocalSettings.php --username-prefix='' < dump.xml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment