#!/bin/bash
#记录备份的时间
echo "-----"$(date +"%y-%m-%d %H:%M:%S")"-----" >> /data/backup_mysql/record.log
#定义变量
MYUSER=root
MYPASSWORD=29749716#@Heiniao
SOCKET=/data/mysql/mysql.sock
MYCMD="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).sql
done
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 {} \;
本文出自 “金宝的博客” 博客,请务必保留此出处http://jinbao.blog.51cto.com/6287622/1758419
原文地址:http://jinbao.blog.51cto.com/6287622/1758419