Toolbox
  • Printable version
 
Toolbox
LANGUAGES
Language
Personal tools
Categories
Wikipedia Affiliate Button
 

MediaWiki backup

From BrightByte

Jump to: navigation, search

Regarding all software published on this site,
please note the software disclaimers page!

Here is a little script that can be used to create a backup of your MediaWiki installation:

#!/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. #
#                                                                  #
####################################################################
 
###############################################
# CHANGE THESE OPTIONS TO MATCH YOUR SYSTEM ! #
###############################################
 
wikidb="daniel_wiki"                 # the database your wiki stores data in
#mysqlopt="-u username -ppassword"   # any options used for interacting with mysql
mysqlopt=""                          # usually empty if username and password are provided in your .my.cnf
 
wikidir=~/www/mw                     # the directory mediawiki is installed in
backupdir=~/bak                      # the directory to write the backup to
 
##################
# END OF OPTIONS #
##################
 
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 --exclude .svn -zcf "$filedump" . || exit $?
 
echo
echo "Done!"
echo "Files to copy to a safe place: $dbdump, $xmldump, $filedump"
 
#######
# END #
#######

It's also in the repository: code or pretty

[talk page]Talk:MediaWiki backup

+z$8frZdyL%68pSU/:>w<:E3.lG-!XIB

Contents

[edit] generic modification suggestions

right after the options part I added:

# 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`
wikidb=$wikiDBname
mysqlopt="--host=$wikiDBserver --user=$wikiDBuser --password=$wikiDBpassword --skip-lock-tables"
# end of additions


Potential issues:

  • on Debian Etch I had to add the --skip-lock-tables to get the script to work
  • this way I kind of ignore the settings of wikiDB and mysqlopt in the options section which is not very polite and desirable

Modifcations worked for my on mediawiki 1.5 and 1.7 Use modifications at your own risk

[edit] Question

What name do we give to the file? backup.php? backup.sh?

It's a bash script. So traditionally, it would be called wikibackup.sh or just wikibackup. It doesn't really matter though, Linux doesn't care much about file extensions. -- Daniel 08:01, 16 October 2008 (UTC)

[edit] Question

Thanks. ^_^

[edit] Options

What do we change here?

  1. mysqlopt="-u username -ppassword"
Insert your database user and password. Note that there is no space after -p -- Daniel 07:32, 22 October 2008 (UTC)

[edit] Question

And how to restore? Is there also a script available?

[edit] Restore ?

Where is the possible restore script ? Easy for the tar, but for sql and xml less straightforward... Tnx.

There's not much to script.
writing a generic script is tricky, because you would want to import either SQL or XML. And you may want to rebuild the image table, or not. etc.
HTH anyway -- Daniel 12:32, 2 February 2009 (UTC)

[edit] little correction of the generic modification suggestions

Bummer! this line doesn't work when there's a "=" in the password:

wikiDBpassword=`grep '^\$wgDB' $wikidir/LocalSettings.php |grep "DBpassword" | cut --delimiter="=" -f2 | cut --delimiter="\"" -f2`

I suggest this, assuming double quotes around the password (and none within):

wikiDBpassword=`grep '^\$wgDB' $wikidir/LocalSettings.php |grep "DBpassword" | cut --delimiter="\"" -f2 | cut --delimiter="\"" -f1`

[edit] Using PHP

 # DATABASE SETTINGS
 DBUSER=`php -r 'define('MEDIAWIKI','true'); require("'${WIKIROOT}'/LocalSettings.php") ; echo $wgDBuser;'`
 DBPASSWORD=`php -r 'define('MEDIAWIKI','true'); require("'${WIKIROOT}'/LocalSettings.php") ; echo $wgDBpassword;'`
 DBNAME=`php -r 'define('MEDIAWIKI','true'); require("'${WIKIROOT}'/LocalSettings.php") ; echo $wgDBname;'`

[edit] Mac DB Problem

Was this script also tested under Mac OS X?


I got the following error when creating the database dump:

wikibackup.sh: line 40: mysqldump: command not found

and the following when creating the XML dump:

DB connection error: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) (localhost)


Using MAMP the socket should be here:

/Applications/MAMP/tmp/mysql/mysql.sock

Altough I don't know how to change that (if that has something to do with the problem at all)

[edit] Mac DB MySQL issue, first part...

Assuming a default installation of XAMPP, I suspect you need to add the following to your ~/.bash_profile:

export PATH="$PATH:/Applications/XAMPP/xamppfiles/bin"

This will allow the backup script to find mysqldump in the $PATH

(XAMPP for Mac OS X v0.7.3)

[edit] What Is the Best Way to Burn Fat

I recently saw this <http>//www.squidoo.com/burn-the-fat-feed-the-muscle-diet-book Burn the Fat book] . I've heard amazing reviews. Tom Venuto wrote the book and it's a proven dieting plan.



The above comments may have been left by visitors.

This site's operators can not take responsibility for the content of such comments.