#!/bin/bash
# Backup script using mysqlhotcopy
# Allows you to set a maintenance page
# Author: Matt Rae
backupdir="/root/mysqlbackup"
days=30
dbname=$1
docroot=$2
tmpindex=$3
if [ $# -ne 3 ]; then
echo "Usage: $0 dbname docroot tmpindex"
echo " dbname : database you want to backup"
echo " docroot : document root for app"
echo " tmpindex : temporary site index in docroot"
exit 1
fi
if [ ! -e $tmpindex ]; then
echo "$tmpindex doesn't exist in $docroot"
exit 1
fi
#put temporary page in place
mv $docroot/index.php $docroot/index.php.bak
cp -p $docroot/$tmpindex $docroot/index.html
#do backup
mkdir -p $backupdir/$(date +%Y-%m-%d) && /usr/bin/mysqlhotcopy --allowold $dbname
#delete old backups $days old
find $backupdir/*/$dbname -maxdepth 0 -mtime +$days -exec /bin/rm -rf {} +
#remove empty backup dirs
rmdir --ignore-fail-on-non-empty /$backupdir/*
#remove temporary page
rm $docroot/index.html
mv $docroot/index.php.bak $docrot/index.php
21:46 <@ justdave> we used to use mysqlhotcopy for our backups until people started using InnoDB
21:46 <@ justdave> mysqlhotcopy doesn't work on InnoDB tables
21:46 < cshields> good to know
21:47 <@ justdave> as long as everything in your DB is MyISAM it works great (and is much faster than mysqldump)