#!/bin/bash
# *************************************************************
# file: mysqldump.sh
# date: 2007-07-04 00:22
# author: (c) by Marko Schulz - <info@tuxnet24.de>
# description: Get a mysqldump of all mysql databases.
# *************************************************************
# name of database user ( must have LOCK_TABLES rights )...
dbUsername="backupuser"
# password of database user...
dbPassword="SeCret"
# path to backup directory...
dbBackup="/data/backup/mysqldump"
# *************************************************************
# program action...
# get current date ( YYYY-MM-DD )...
date=$( date +%Y-%m-%d )
# create backup directory if not exists...
[ ! -d "$dbBackup" ] && mkdir -p $dbBackup
# delete all old mysqldumps...
find $dbBackup/ -type f -name '*.sql.gz' -exec rm -rf {} ';' >/dev/null 2>&1
# loop all databases...
for db in $( mysql -u $dbUsername --password=$dbPassword -Bse "show databases" ); do
# get mysqldump of current database...
mysqldump -u $dbUsername --password=$dbPassword --opt --databases $db | gzip -9 >${dbBackup}/${db}-${date}.sql.gz
done
# *************************************************************
# EOF