mysql 数据备份脚本
架构:
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=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 if [ $? -ne 0 ];then echo "$BACKTIME Mysql slave ${DBNAME}_full error!" >> /tmp/back_error.txt mail -s "$DBNAME full back error !!" [email protected] < /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 !!" [email protected] < /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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。