#!/bin/bash#auto backup mysql every database; #date 2014.07.07#author firxiao### mysql_config### #HOST = "localhost" # #mysql主机IPUSER = "xxxx" # #用户名PASSWD = "xxxx" # #密码BACKUPDIR = '/backup ' # #备份目录 # # # ############### #DATE = ' date +%y%m%d ' # #当前日期 (no need to change) m= ' date +%y%m ' # #当前月 (no need to change) Function createdir () # #判断备份目录是否存在 does not exist create {while [ ! -d $BACKUPDIR ]; do echo "$BACKUPDIR is not Exits, will create now " mkdir -p $ backupdirdonecd $BACKUpdirwhile [ ! -d "$DATE" &NBSP;];d O mkdir $DATEdonewhile [ ! -d "$M" &NBSP;];d o mkdir $Mdone}function showdatabase () ## Find out which libraries are in MySQL {mysql -h $HOST -u$USER -p$PASSWD -e ' show databases; ' |grep -v ' Database ' |grep -v ' Information_schema ' > /tmp/mysqldblist} function backup () # #备份并将备份移到当前月份文件夹 {while read linedo mysqldump -h $HOST -u$user -p$PASSWD $LINE > $DATE/$LINE $date.sqldone < /tmp/mysqldblistmysqldump -h $HOST -u$USER -p$PASSWD --all-database > $DATE/all$date.sqltar cvfj $DATE .tar.gz $DATErm -rf $DATEmv $DATE .tar.gz $M/}createdir && showdatabase && backup # #开始备份