Fullsitebackup

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 a 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.


 * 1) !/bin/bash
 * 2) fullsitebackup.sh V1.2
 * 3) Full backup of website files and database content.
 * 4) A number of variables defining file location and database connection
 * 5) information must be set before this script will run.
 * 6) Files are tar'ed from the root directory of the website. All files are
 * 7) saved. The MySQL database tables are dumped without a database name and
 * 8) and with the option to drop and recreate the tables.
 * 9) 05-Jul-2007 - Quick adaptation for MediaWiki (currently testing)
 * 10) March 2007 Updates - Version for Drupal
 * 11) - Updated script to resolve minor path bug
 * 12) - Added mysql password variable (caution - this script file is now a security risk - protect it)
 * 13) - Generates temp log file
 * 14) - Updated backup and restore scripts have been tested on Ubunutu Edgy server w/Drupal 5.1
 * 15) - Enjoy! BristolGuy
 * 16) Parameters:
 * 17) tar_file_name (optional)
 * 18) Configuration
 * 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) tar_file_name (optional)
 * 6) Configuration
 * 1) Parameters:
 * 2) tar_file_name (optional)
 * 3) Configuration
 * 1) Configuration
 * 1) Configuration

dbname="wikidb" # (e.g.: dbname=wikidb) dbhost="localhost" dbuser="" # (e.g.: dbuser=wikiuser) dbpw="" # (e.g.: dbuser password)
 * 1) Database connection information

webrootdir="/var/www/w" # (e.g.: webrootdir=/home/user/public_html)
 * 1) Website Files


 * 1) Variables
 * 1) Variables

tarnamebase=sitebackup- datestamp=`date +'%m-%d-%Y'`
 * 1) Default TAR Output File Base Name

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

tempdir=$datestamp
 * 1) Temporary Directory


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

if test "$1" = "" then tarname=$tarnamebase$datestamp.tgz else tarname=$1 fi

echo "Beginning mediawiki site backup using fullsitebackup.sh ..." > $logfile echo " Creating temp working dir ..." >> $logfile mkdir $tempdir
 * 1) Begin logging
 * 1) Begin logging
 * 1) Create temporary working directory
 * 1) Create temporary working directory

echo " TARing website files into $webrootdir ..." >> $logfile cd $webrootdir tar cf $startdir/$tempdir/filecontent.tar.
 * 1) TAR website files
 * 1) TAR website files

echo " Dumping mediawiki database, using ..." >> $logfile echo " user:$dbuser; database:$dbname host:$dbhost " >> $logfile cd $startdir/$tempdir mysqldump --user=$dbuser --password=$dbpw --add-drop-table $dbname > dbcontent.sql
 * 1) sqldump database information
 * 1) sqldump database information

echo " Creating final compressed (tgz) TAR file: $tarname ..." >> $logfile tar czf $startdir/$tarname filecontent.tar dbcontent.sql
 * 1) Create final backup file
 * 1) Create final backup file

echo " Removing temp dir $tempdir ..." >> $logfile cd $startdir rm -r $tempdir
 * 1) Cleanup
 * 1) Cleanup

endtime=`date` echo "Backup completed $endtime, TAR file at $tarname. " >> $logfile
 * 1) Exit banner
 * 1) Exit banner

Weblinks

 * Updated fullsitebackup.sh for Drupal