Fullsiterestore

While looking for a quick and reliable way to get complete working backups, I stumbled over these shell scripts. They were originally designed for Drupal, but can easily adapted for use with MediaWiki.

Fullsitebackup creates a complete backup of the files of an MediaWiki installation and of it's database. Fullsiterestore restores both. Also, the scripts can be used to migrate an MediaWiki installation from one to another host.

Please note that these scripts have some limitations, have some security risks, and are not tested thoroughly.

To do: Testing; handling of charsets; handling of innodb tables and lots more.

License: The original scripts are part of the Drupal handbook; the pages were written by different contributors and can be used in accordance with the Creative Commons Attribution-ShareAlike 2.0 License.

dbname="wikidb" # (e.g.: dbname=wikidb) dbhost="localhost" # dbuser="" # (e.g.: dbuser=wikiuser) dbpw="" # database user password
 * 1) !/bin/bash
 * 2) fullsiterestore.sh v1.1
 * 3) Restore of website file and database content made with full site backup.
 * 4) A number of variables defining file location and database connection
 * 5) information must be set before this script will run.
 * 6) This script expects a compressed tar file (tgz) made by fullsitebackup.sh.
 * 7) Website files should be in a tar file named filecontent.tar, and database
 * 8) content should be in a sqldump sql file named dbcontent.sql. This script
 * 9) expects the sql to drop the table before readdding the data. In other words,
 * 10) it does not do any database preparation.
 * 11) 05-Jul-2007 - Quick adaptation for MediaWiki (currently testing)
 * 12) March 2007 Updates - Version for Drupal
 * 13) - Updated script to resolve minor path bug
 * 14) - Added mysql password variable (caution - this script file is now a security risk - protect it)
 * 15) - Generates temp log file
 * 16) - Updated backup and restore scripts have been tested on Ubunutu Edgy server w/Drupal 5.1
 * 17) - Enjoy! BristolGuy
 * 18) Parameters:
 * 19) tarfile # name of backup file to restore
 * 20) Database connection information
 * 1) - Generates temp log file
 * 2) - Updated backup and restore scripts have been tested on Ubunutu Edgy server w/Drupal 5.1
 * 3) - Enjoy! BristolGuy
 * 4) Parameters:
 * 5) tarfile # name of backup file to restore
 * 6) Database connection information
 * 1) Parameters:
 * 2) tarfile # name of backup file to restore
 * 3) Database connection information
 * 1) Database connection information
 * 1) Database connection information

webrootdir="/var/www/w" # (e.g.: where you keep your mediawiki directory structure)
 * 1) Website location
 * 1) Variables
 * 1) Variables

startdir=`pwd` # return of pwd populates statdir var logfile=$startdir+"fullsite.log" # file path and name of log file to use
 * 1) Execution directory (script start point)

datestamp=`date +'%Y-%m-%d'` # uses US format tempdir=$datestamp
 * 1) Temporary Directory

echo "Beginning mediawiki site restore using \'fullsiterestore.sh\' ..." > $logfile
 * 1) Begin logging
 * 1) Begin logging


 * 1) Input Parameter Check
 * 1) Input Parameter Check

if [ $# -eq 0 ] then echo " Usage: sh fullsiterestore.sh {backupfile.tgz}" echo "" exit fi
 * 1) If no input parameter is given, echo usage and exit

tarfile=$1

if [ ! -f "$tarfile" ] then echo " Can not find file: $tarfile" >> $logfile echo " Exiting ..." >> $logfile exit fi
 * 1) Check that the file exists

if [ ! -d "$webrootdir" ] then echo " Invalid internal parameter: webrootdir" >> $logfile echo " Directory: $webrootdir does not exist" >> $logfile echo " Exiting ..." >> $logfile exit fi
 * 1) Check that the webroot directory exists

echo " Creating temp working dir ..." >> $logfile mkdir $tempdir cd $tempdir echo " unTARing db and file tgz files ..." >> $logfile tar xzf $startdir/$tarfile
 * 1) Create temporary working directory and expand tar file
 * 1) Create temporary working directory and expand tar file

echo " Removing old files from $webrootdir ..." >> $logfile rm -r $webrootdir/*
 * 1) Remove old website files
 * 1) Remove old website files

echo " unTARing website files into $webrootdir ..." >> $logfile cd $webrootdir tar xf $startdir/$tempdir/filecontent.tar
 * 1) unTAR website files
 * 1) unTAR website files

cd $startdir/$tempdir echo " Restoring database ..." >> $logfile echo " user: $dbuser; database: $dbname; host: $dbhost" >> $logfile echo "use $dbname; source dbcontent.sql;" | mysql --password=$dbpw --user=$dbuser --host=$dbhost
 * 1) Load database information
 * 1) Load database information

echo " Cleaning up ..." >> $logfile cd $startdir sudo rm -r $tempdir
 * 1) Cleanup
 * 1) Cleanup

endtime=`date` echo "Restoration completed $endtime for $tarfile. " >> $logfile
 * 1) Exit banner
 * 1) Exit banner

Weblinks

 * Updated fullsiterestore.sh fur Drupal