#! /bin/sh
############################################################################
# Copyright (C) 2008 by fradeff@akademia.ch #
# #
# This program is free software; you can redistribute it and#or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the #
# Free Software Foundation, Inc., #
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
# Usage:
# mysqldumplocal.sh
# sauvegarder toutes les bases MySQL sauf certaines
# Required:
# mysqldump, awk, gzip
# source http://lists.nyphp.org/pipermail/talk/2004-October/012361.html
# Adapted FR, fradeff@akademia.ch, radeff.red
# History 1 octobre 2008, created FR
############
login=root #root login mysql
password=xxx #passwd mysql
memoire=30 #the number of days for the backup
#path to mysql data directory
mysql_dir=/var/lib/mysql #on debian
#mysql_dir=/usr/local/mysql/data #on unix
#path to backup
mysql_backup=/home/radeff/backup/mysql #local
#on unix
#db to excludes
test=cake_test
test1=achats_dinf
clear
#find the db and exclude somes
ls -al $mysql_dir | grep ^d | egrep -v '\.[\.]?' | grep -v $test | grep -v $test1 | awk '{print $8}' | while read i
#begin loop on results
do
#dump db, name prededed by date, extension sql
echo "mysqldump $i > $mysql_backup/$(date +'%Y%m%d_%Hh%M')_$i.sql"
mysqldump -u $login -p$password $i > $mysql_backup/$(date +'%Y%m%d_%Hh%M')_$i.sql
#zip the backups
gzip $mysql_backup/$(date +'%Y%m%d_%Hh%M')_$i.sql
done
#end loop on results
#destroy backups older than memoire days
find $mysql_backup -mtime +$memoire -name "*.gz" -type f -exec rm {} \;
echo "Backup OK on all MySQL requested DB's"
#