#!/bin/sh
#
# $Id: mysqlbackup.sh 216 2010-11-06 16:38:30Z rick $
# Poor mans mysql database backup.
# Rick van der Zwet <info@rickvanderzwet.nl>


BACKUP_ROOT='/usr/local/backup/mysqlbackup'
MYSQL_AUTH='-uroot'
export PATH=$PATH:/usr/local/bin

# All available database
DATABASES=`echo 'show databases' | mysql --skip-column-names $MYSQL_AUTH`

BACKUP_TODAY=`date "+$BACKUP_ROOT/%Y/%m/%d/"`
mkdir -p $BACKUP_TODAY
# Dump and compress
for DATABASE in $DATABASES; do
  TIMETAG=`date "+%H:%M:%S"`
  mysqldump $MYSQL_AUTH --skip-lock-tables $DATABASE | gzip > $BACKUP_TODAY/$DATABASE-$TIMETAG.sql.gz
done

