Skip to content

Instantly share code, notes, and snippets.

@MichaelCurrie
Last active October 12, 2020 05:29
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 MichaelCurrie/a36bb5746a19e4b77160296baa14365d to your computer and use it in GitHub Desktop.
Save MichaelCurrie/a36bb5746a19e4b77160296baa14365d to your computer and use it in GitHub Desktop.
How to back up a MediaWiki server hosted on a remote Debian machine
# A script showing how to back up a MediaWiki server hosted on a remote Debian machine
# I run each line manually myself
# SUMMARY: Basically there are five things you should extract from the mediawiki server:
# 1. LocalSettings.php: Get this from /var/www/mediawiki/LocalSettings.php
# 2. images.zip: A zip file of /var/www/mediawiki/images which contains all the image data
# 3. dbdump20201011.sql: A single .sql file which is a dump of every table in the /var/www/ MySQL mediawiki database,
# which you can create by running mysqldump
# 4. pedia_full_dump.xml: The content, by running php /var/www/mediawiki/maintenance/dumpBackup.php --full > pedia_full_dump.xml
# 5. mediawiki.zip: A zip file of /var/www/mediawiki entirely (just in case we have other media or config stuff we need)
# This procedure shows how to get these files, and then upload them off the remote machine using Dropbox.
# Locate mediawiki
sudo su
root@mediawiki /# locate LocalSettings.php
# /var/www/mediawiki/includes/NoLocalSettings.php
# /var/www/mediawiki/LocalSettings.php
# For me, I had to first remind myself which database is the one to care about:
# which of mediawiki, mediawiki2, mediawiki3, from /var/lib/mysql/,
# because I had previously saved some backups of the database called mediawiki2 and mediawiki3 and I forgot that mediawiki was the
# database with the actual data
vim /var/www/mediawiki/LocalSettings.php
# Note the CPU is running at 100%! Geez. Hackers.
htop
# Note that we're running debian:
cat /etc/os-release
# PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
# NAME="Debian GNU/Linux"
# VERSION_ID="8"
# VERSION="8 (jessie)"
# ...
# For me, I had to first fix a corrupted searchindex table issue, because:
# admin@mediawiki www/mediawiki$ sudo mysqldump -p --all-databases > ~/Dropbox/mediawikiDB20201011.sql
# mysqldump: Got error: 144: Table './mediawiki/searchindex' is marked as crashed and last (automatic?) repair failed when using LOCK TABLES
# Solve with: https://stackoverflow.com/questions/8843776/
sudo service mysql stop
sudo su
cd /var/lib/mysql/mediawiki
myisamchk -f searchindex
sudo service mysql start
# Check disk usage:
df
# Uh oh! I have no free space so I won't be able to sync Dropbox or dump the database, etc.
# So let's clear some space (delete logfiles etc)
cd /
du -s * | sort -rn | cut -f2- | xargs -d "\n" du -sh
# DROPBOX
# Set up Dropbox so I can upload away from the EC2 instance
# DO THIS AS A USER NOT AS ROOT. So first exit from root:
exit
# Install dependencies for Dropbox:
# https://www.dropboxforum.com/t5/Dropbox-installs-integrations/Headless-install-on-Debian-libglapi-so-0-cannot-open-shared/td-p/396457
sudo apt-get install libc6
sudo apt-get install libglapi-mesa
sudo apt-get install libxdamage1
sudo apt-get install libxfixes3
sudo apt-get install libxcb-glx0
sudo apt-get install libxcb-dri2-0
sudo apt-get install libxcb-dri3-0
sudo apt-get install libxcb-present0
sudo apt-get install libxcb-sync1
sudo apt-get install libxshmfence1
sudo apt-get install libxxf86vm1
# Install Dropbox headless for linux:
# https://www.dropbox.com/install-linux
cd ~
cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
~/.dropbox-dist/dropboxd
# These steps are approximate, I'm typing them from memory:
wget https://www.dropbox.com/download?dl=packages/dropbox.py dropbox.py
chmod +x dropbox.py
./dropbox.py -i
# Link it to a dropbox account which doesn't have much data or else it will waste time downloading data. Then:
./dropbox.py start
# Keep monitoring the status until it's up to date:
./dropbox.py status
# Now turn off mediawiki:
sudo service mysql stop
# sudo systemctl start mysql
# sudo systemctl stop mysql
# sudo systemctl restart mysql
# sudo systemctl status mysql
cd ~/Dropbox
mkdir mw_backup
# =============================================
# ----------------------------------------------
# 1. Copy LocalSettings.php
cp /var/www/mediawiki/LocalSettings.php ~/Dropbox/mw_backup
# ----------------------------------------------
# 2. Specially zip the images folder because in practice that's what we'll use:
zip -r ~/Dropbox/mw_backup/images.zip /var/www/mediawiki/images
# ----------------------------------------------
# 3. Dump the database to a file on Dropbox
# (do this as admin not as root, or you have to run: chown admin ~/Dropbox/mw_new/mediawikiDB20201011-5.sql)
sudo service mysql start
sudo mysqldump -p --databases mediawiki > ~/Dropbox/mw_backup/mediawikiDB20201011-5.sql
sudo service mysql stop
# ----------------------------------------------
# 4. Get an XML dump of the content of the wiki
sudo service mysql start
php /var/www/mediawiki/maintenance/dumpBackup.php --full > ~/Dropbox/mw_backup/pedia_full_dump.xml
sudo service mysql stop
# ----------------------------------------------
# 5. [OPTIONAL] Copy the entire mediawiki folder (which contains images and config info):
# This is redundant for #1 and #2 but oh well, it's nice to have it separately.
zip -r ~/Dropbox/mw_backup/mediawiki.zip /var/www/mediawiki
# =============================================
# Check the status of Dropbox
# Keep monitoring the status until it's up to date:
./dropbox.py status
# Download or sync the files from the Dropbox site on your local machine!
# Then, unlink Dropbox on the mediawiki remote instance
# On the dropbox.com website, visit the Account -> Settings -> "security" tab
# Delete the mediawiki EC2 instance that's linked.
# Then check that Dropbox is not linked:
./dropbox.py status
# but this doesn't seem to really work, so possibly this:
# at this point I didn't really care, I'm just going to shut down the instance anyway.
https://superuser.com/questions/1472346/
# Goodbye old mediawiki server:
sudo shutdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment