#!/bin/sh
# -----------------------------
#auth:lrm
#date:20120816
#database  backup
db_user="root"
db_passwd="123456"
db_host="localhost"
db_name1="1"
db_name2="2"
db_name3="3"
db_name4="4"
# the directory for story your backup file.
backup_dir="/data/xixi_bak/mysql_backup/"

# date format for backup file (dd-mm-yyyy)
#time="$(date +"%Y-%m-%d:%H")"
time="$(date +"%Y-%m-%d")"

# mysql, mysqldump and some other bin's path
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
MKDIR="$(which mkdir)"
RM="$(which rm)"
MV="$(which mv)"
GZIP="$(which gzip)"
$MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db_name1 --default-character-set=utf8 --opt -Q -R --skip-lock-tables | $GZIP -9 > "$backup_dir/$time.$db_name1.gz"
$MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db_name2 --default-character-set=utf8 --opt -Q -R --skip-lock-tables | $GZIP -9 > "$backup_dir/$time.$db_name2.gz"
$MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db_name3 --default-character-set=utf8 --opt -Q -R --skip-lock-tables | $GZIP -9 > "$backup_dir/$time.$db_name3.gz"
$MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db_name4 --default-character-set=utf8 --opt -Q -R --skip-lock-tables | $GZIP -9 > "$backup_dir/$time.$db_name4.gz"


find /data/xixi_bak/mysql_backup/ -mtime +7 -type f | xargs rm -rf