Created
February 17, 2014 23:26
-
-
Save d6e/9061373 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. # | |
# # | |
# 1st Mod: http://www.mediawiki.org/wiki/User:Kaotic # | |
# 2nd Mod: http://www.mediawiki.org/wiki/User:Megam0rf # | |
# 3rd Mod: http://www.mediawiki.org/wiki/User:Robkam # | |
# # | |
# This script comes without any warranty, use it at your own risk. # | |
# # | |
#################################################################### | |
############################################### | |
# CHANGE THESE OPTIONS TO MATCH YOUR SYSTEM ! # | |
############################################### | |
wikidb="wikidb" # the database your wiki stores data in | |
mysqlopt="--user=XXXX --password=XXXX" # usually empty if username and password are provided in your .my.cnf | |
wikidir=/var/lib/mediawiki # the directory mediawiki is installed in | |
backupdir=~/bak # the directory to write the backup to | |
chrset="--default-character-set=binary" # latin1, utf8, binary, etc. Check your wiki's LocalSettings.php | |
################## | |
# END OF OPTIONS # | |
################## | |
timestamp=`date +%Y-%m-%d` | |
#################################### | |
# Put the wiki into Read-only mode # | |
#################################### | |
echo | |
echo "Putting the wiki in Read-only mode..." | |
maintmsg="\$wgReadOnly = 'Dumping Database, Access will be restored shortly';" | |
grep "?>" "$wikidir"/LocalSettings.php > /dev/null | |
if [ $? -eq 0 ]; | |
then | |
sed -i "s/?>/$maintmsg?>/ig" "$wikidir"/LocalSettings.php | |
else | |
echo "$maintmsg?>" >> "$wikidir"/LocalSettings.php | |
fi | |
#################################### | |
dbdump="$backupdir/wiki-$timestamp.sql.gz" | |
filedump="$backupdir/wiki-$timestamp.files.tgz" | |
xmldump="$backupdir/wiki-$timestamp.xml.gz" | |
echo | |
echo "Wiki backup:\n-------------" | |
echo " Database: $wikidb\n Directory: $wikidir\n Backup to: $backupdir" | |
echo "\ncreating database dump \t$dbdump..." | |
mysqldump $chrset $mysqlopt "$wikidb" | gzip > "$dbdump" || exit $? | |
echo "creating file archive \t$filedump..." | |
cd "$wikidir" | |
tar --exclude .svn -zcf "$filedump" . || exit $? | |
echo "creating XML dump \t$xmldump..." | |
cd "$wikidir/maintenance" | |
php -d error_reporting=E_ERROR dumpBackup.php --full | gzip > "$xmldump" || exit $? | |
########################################## | |
# Put the wiki back into read/write mode # | |
########################################## | |
echo | |
echo "Bringing the wiki out of Read-only mode..." | |
grep "?>" "$wikidir"/LocalSettings.php > /dev/null | |
if [ $? -eq 0 ]; | |
then | |
sed -i "s/$maintmsg?>/?>/ig" "$wikidir"/LocalSettings.php | |
else | |
sed -i "s/$maintmsg//ig" "$wikidir"/LocalSettings.php | |
fi | |
########################################## | |
echo | |
echo "Done!" | |
echo "Files to copy to a safe place:" | |
echo "$dbdump," | |
echo "$filedump," | |
echo "$xmldump" | |
####### | |
# END # | |
####### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment