#!/bin/bash
#记录备份的时间
echo "-----"$(date +"%y-%m-%d %H:%M:%S")"-----" >> /data/backup_mysql/record.log#定义变量
MYUSER=root
MYPASSWORD=29749716#@HeiniaoSOCKET=/data/mysql/mysql.sockMYCMD="mysql -u $MYUSER -p$MYPASSWORD -S $SOCKET"MYDUMP="mysqldump -u $MYUSER -p$MYPASSWORD -S $SOCKET"BACKUPDIR=/data/backup_mysql#正式备份
for db in `$MYCMD -e "show databases;"|sed '1,2d' | egrep -v "mysql|performance_schema"`
do $MYDUMP $db > ${BACKUPDIR}/${db}_$(date +%F).sqldone cd ${BACKUPDIR} tar czvf ${BACKUPDIR}/$(date +%F).tar.gz ./*_$(date +%F).sql rm -rf ${BACKUPDIR}/*.sql find ${BACKUPDIR} -mtime +30 -name "*.sql.tar.gz" -exec rm -rf {} \;