Skip to content

Instantly share code, notes, and snippets.

@pklaus
Created December 11, 2010 19:06
Show Gist options
  • Save pklaus/737577 to your computer and use it in GitHub Desktop.
Save pklaus/737577 to your computer and use it in GitHub Desktop.
wikibackup – A Basic Backup Script for MediaWiki
#!/bin/sh
####################################################################
# #
# Basic Backup Script for MediaWiki. #
# Created by Daniel Kinzler, brightbyte.de, 2008 #
# #
# This script may be freely used, copied, modified and distributed #
# under the sole condition that credits to the original author #
# remain intact. #
# #
# This script comes without any warranty, use it at your own risk. #
# #
####################################################################
####################################################################
# #
# Edited by Philipp Klaus, 2010 #
# #
####################################################################
#################
# RESTORE INFO: #
#################
# move the tar to backupdir and run tar -xf file.tar
# * restore sql: gunzip -c wiki-timestamp.sql.gz | mysql dbname>
# * __OR__ restore xml: php maintenance/importDump.php wiki-timestamp.xml.gz
# (for more info on importing XML dumps, seehttp://www.mediawiki.org/wiki/Manual:Importing_XML_dumps )
###############################################
# CHANGE THESE OPTIONS TO MATCH YOUR SYSTEM ! #
###############################################
wikidir=/var/www/zapfwiki/wiki # the directory mediawiki is installed in
backupdir=~/wikibackup # the directory to write the backup to
##################
# END OF OPTIONS #
##################
# added by OZ
test ! -d $backupdir && mkdir $backupdir
wikiDBserver=`grep '^\$wgDB' $wikidir/LocalSettings.php |grep "DBserver" | cut --delimiter="=" -f2 | cut --delimiter="\"" -f2`
wikiDBname=`grep '^\$wgDB' $wikidir/LocalSettings.php |grep "DBname" | cut --delimiter="=" -f2 | cut --delimiter="\"" -f2`
wikiDBuser=`grep '^\$wgDB' $wikidir/LocalSettings.php |grep "DBuser" | cut --delimiter="=" -f2 | cut --delimiter="\"" -f2`
#wikiDBpassword=`grep '^\$wgDB' $wikidir/LocalSettings.php |grep "DBpassword" | cut --delimiter="=" -f2 | cut --delimiter="\"" -f2`
wikiDBpassword=`grep '^\$wgDB' $wikidir/LocalSettings.php |grep "DBpassword" | cut --delimiter="\"" -f2 | cut --delimiter="\"" -f1`
wikidb=$wikiDBname
mysqlopt="--host=$wikiDBserver --user=$wikiDBuser --password=$wikiDBpassword --skip-lock-tables"
# end of additions
timestamp=`date +%Y-%m-%d`
dbdump="$backupdir/wiki-$timestamp.sql.gz"
xmldump="$backupdir/wiki-$timestamp.xml.gz"
filedump="$backupdir/wiki-$timestamp.files.tgz"
echo "Wiki backup. Database: $wikidb; Directory: $wikidir; Backup to: $backupdir"
echo
echo "creating database dump $dbdump..."
mysqldump --default-character-set=latin1 $mysqlopt "$wikidb" | gzip > "$dbdump" || exit $?
echo
echo "creating XML dump $xmldump..."
cd "$wikidir/maintenance"
php -d error_reporting=E_ERROR dumpBackup.php --full | gzip > "$xmldump" || exit $?
echo
echo "creating file archive $filedump..."
cd "$wikidir"
tar -zcf "$filedump" . || exit $?
echo
echo "Done!"
echo "Files to copy to a safe place: $dbdump, $xmldump, $filedump"
#######
# END #
#######
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment