#!/bin/bash
#
# This script will run in a loop for every database on the server and
# create a backup file per db. DUMPOPTIONS currently works with MySQL 4.0.24
# change it if you are using a different version
#
# Customize the variables below to adjust this script for your environment
# This should also work in ksh (Korn Shell)
#
PSSWD="mypassword"
BDIR="/backup/dir/"
MYSQL="/usr/local/mysql/bin/mysql"
DBDUMP="/usr/local/mysql/bin/mysqldump"
DUMPOPTIONS="--add-drop-table --add-locks --complete-insert --disable-keys --all
--extended-insert --flush-logs --lock-tables --quick --quote-names --password=${PSSWD}"
COMPRESS="/bin/gzip -f"
TODAY=`date +'%d%m%Y'`
for DB in `echo 'show databases' | ${MYSQL} -p${PSSWD} --column-names=false` ; do
DUMPFILE="${BDIR}${DB}_${TODAY}.sql"
ERRORMSG="ERROR: Backup of ${DB} failed"
echo "Backing up ${DB} ..."
${DBDUMP} ${DUMPOPTIONS} ${DB} > ${DUMPFILE}
if [ $? -eq 0 ] ; then
${COMPRESS} ${DUMPFILE} &
else
echo ${ERRORMSG}
fi
echo ""
echo ""
done
|