#!/bin/bash

PATH=/usr/sbin:/sbin:/bin:/usr/bin

MyUSER="Your Username Here"
MyPASS="Your Password Here"
MyHOST="localhost" #Usually 'localhost', but if you know what you are doing, please change it

MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"

DEST="/backup" #destination folder, /backup is default folder, you need to create it first
MDB="$DEST/mysql" #i put all database backup under mysql folder, you can change it to anyname

HOST="$(hostname)"

NOW="$(date +"%d-%m-%Y")"
FILE=""

DBS=""

IGGY="test mysql"

DBS="$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')"

for db in $DBS
do
	skipdb=-1
	if [ "$IGGY" != "" ];
	then
	for i in $IGGY
		do
			[ "$db" == "$i" ] && skipdb==1 || :
		done
	fi

	if [ "$skipdb" == "-1" ] ; then
		FILE="$MDB/$db.$HOST.gz"
		$MYSQLDUMP -u $MyUSER -h $MyHOST -p$MyPASS --complete-insert $db | $GZIP -9 > $FILE
                echo "Backup $FILE.....DONE"
	fi
done