架构:
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 !!" 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