#! /bin/sh

# -------------------------------------
#
# This script is freely distributed under the GPL
# -------------------------------------

# Configuration variables
# -------------------------------------

USER='MySQL-USER'
PASS='MySQL-PASSWORD'
HOST='localhost'
BACKUPDIR='/var/backups/mysql'

# Script execution
# -------------------------------------

data=`date +%Y%m%d`

for i in `mysql -u $USER -h $HOST -p$PASS -Bse 'show databases'`; do
  echo 'Processing '$i

  mysqldump --add-drop-table -u$USER -p$PASS $i |  gzip -9 > $BACKUPDIR/$data-$i.sql.gz
done

find $BACKUPDIR -type f -mtime +7 -exec rm -f {} \;