mysql简单备份脚本
#!/bin/bash #army.han #2016-11-11 #new_gj_DBbackup
#备份路径配置 GSdir='/data/dbbackup/mysqlDB' TIME=`date "+%Y%m%d"` MYSQL=`which mysql` MYSQLDUMP=`which mysqldump` GSbackup(){ DBhost=$1 DBuser=$2 DBpass=$3 DBname=`$MYSQL -h$DBhost -u$DBuser -p$DBpass -e "show databases;"|egrep -v "information_schema|performance_schema|mysql|Database"` for i in $DBname;do [ -d $GSdir ]||mkdir -pv $GSdir $MYSQLDUMP -h$DBhost -u$DBuser -p$DBpass -R $i > ${GSdir}/$DBhost${i}_$TIME.sql [[ $? -ne 0 ]] && echo "$i database backup failed" >>/tmp/mysql_error.log cd $GSdir tar -zcf $DBhost-${i}_$TIME.tar.gz $DBhost${i}_$TIME.sql && rm -f $DBhost${i}_$TIME.sql done } #添加备份数据库,可以备份多个,直接调用函数就OK GSbackup localhost root 123456 find ${GSdir}/* -ctime +7 -type f -name "*.tar.gz" -exec rm -f {} \;