Dashboard > HOW-TOS > ... > optimize mysql tables > mysqlhotcopy backup script
HOW-TOS Log In   View a printable version of the current page.
mysqlhotcopy backup script
Added by Matt Rae, last edited by Matt Rae on Aug 22, 2006  (view change)
Labels: 
(None)

#!/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)

Posted by Corey Shields at Aug 23, 2006 21:48 | Permalink
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.7 Build:#524 Jul 28, 2006) - Bug/feature request - Contact Administrators