#!/bin/bash

# $Id: mysql_quick_back.sh 31 2007-03-13 19:57:40Z damonp $
#
# Shell script to backup all dbs of MySQL server.
#
# Copyright (c) 2007 Damon Parker < damonp@damonparker.org >
# Licensed under the GNU GPL.  See http://www.gnu.org/licenses/gpl.html

# This script is not supported in any way.  Use at your own risk.
# 

# START configure 
# MySQL user, needs SELECT privileges 
# Create a new user with these permissions!  More secure than using a user
# with full permissions
user=

# MySQL password
pass=

# admin email address
adminemail=

# backup location without trailing slash
# set to current directory
backuppath=.
# or set to your home directory
#backuppath=/home/admin/db_backs

# END configure

now=`date +"%Y%m%d-%k%M"`
host=`hostname`

mysqldump --all-databases --user=$user --password=$pass | gzip > $backuppath/db_dump-$now.gz

quickback=`basename $0`
dumpstat=`ls -lh $backuppath/db_dump-$now.gz`

if [[ -n "$adminemail" && -f "$backuppath/db_dump-$now.gz" ]]; then
	/bin/mail -s "MySQL Backup For $host" "$adminemail" <<EOF
$quickback has completed.
$dumpstat
	
EOF
elif [ -n "$adminemail" ]; then
	/bin/mail -s "MySQL Backup For $host" "$adminemail" <<EOF
$quickback has failed.
Unable to create $backuppath/db_dump-$now.gz


EOF
fi



