首页 > 代码库 > mysql 数据备份脚本

mysql 数据备份脚本

架构:

wKioL1RcK4CQT_KhAABVrSCFybE955.jpg

slave:

#!/bin/bash
#
DATATIME=`date -d "yesterday" +%F`
BACKTIME=`date +"%Y-%m-%d %H:%M:%S"`
BACKUP_DIR=‘/data/dbback‘
MYSQL_USER=‘root‘
MYSQL_PASSWORD=‘123456‘
DBNAME=‘fa‘
FTP_HOST=‘192.168.0.20‘
FTP_USER=backer
FTP_USERPASS=backer
FTP_PORT=10011
[ ! -d $BACKUP_DIR/$DATATIME ] && mkdir $BACKUP_DIR/$DATATIME
mysqldump -u $MYSQL_USER -p${MYSQL_PASSWORD} --master-data=http://www.mamicode.com/2 --lock-all-tables --flush-logs --default-character-set=utf8 -R $DBNAME | gzip -9 >$BACKUP_DIR/$DATATIME/$DBNAME${DATATIME}_full.sql.gz 2> /tmp/back_error.txt"$BACKTIME Mysql slave ${DBNAME}_full error!" >> /tmp/back_error.txt
        mail -s "$DBNAME full back error !!" zhenglm@163.com < /tmp/back_error.txt
else
        cd $BACKUP_DIR/$DATATIME/
        md5sum $DBNAME${DATATIME}_full.sql.gz > $DBNAME${DATATIME}_full.md5.txt
        echo "$BACKTIME back Mysql slave ${DBNAME}_full ok " >/tmp/back_log.txt
        mail -s "Mysql data back ok !!" zhenglm@163.com < /tmp/back_log.txt
fi
find $BACKUP_DIR/ -type d -mtime +32 -exec rm -rf {} \; >/dev/null 2>&1

lftp -p $FTP_PORT $FTP_HOST -u $FTP_USER,$FTP_USERPASS <<EOF
mkdir $DATATIME
cd $DATATIME
put $BACKUP_DIR/$DATATIME/$DBNAME${DATATIME}_full.sql.gz
put $BACKUP_DIR/$DATATIME/$DBNAME${DATATIME}_full.md5.txt
exit
EOF
exit 0

本文出自 “技术小菜” 博客,请务必保留此出处http://390892467.blog.51cto.com/2006821/1573919

mysql 数据备份脚本