xtrabackup自动全备份脚本
发表于:2025-01-23 作者:千家信息网编辑
千家信息网最后更新 2025年01月23日,xtrabackup自动全备份脚本,具有发送邮件和主从判断功能.##set environment##. ~/.bash_profileBASEDIR="/data_bak"SPACE_RATE=95
千家信息网最后更新 2025年01月23日xtrabackup自动全备份脚本xtrabackup自动全备份脚本,具有发送邮件和主从判断功能.
##set environment##
. ~/.bash_profile
BASEDIR="/data_bak"
SPACE_RATE=95 #space rate 95
SPACE_ROOM=10485760 #10GB
WORKPATH=/data_bak/mysqlbackup/percona
DATETIME=`date '+%Y%m%d%H%M'`
INNOBACKUPEX="/usr/bin/innobackupex-1.5.1"
MYSQL="/home/mysqlapp/product/bin/mysql"
BACKUP_USER="root"
BACKUP_PASSWD="******"
BACKUP_HOST="localhost"
BACKUP_PORT="3306"
DEFAULTS_FILE="/home/mysqlapp/config/my.cnf"
SOCKET="/home/mysqlapp/dbdata/mysqld.sock"
DATE_VAR=`date +%F_%H-%M-%S`
MAIL_LIST="xianyezhao@richinfo.cn"
MAIL_BIN="/home/crond/bsmtp"
MAIL_IP="*****"
#sent mail:0 error backup; 1 success backup
my_sentmail()
{
if [ $1 == 1 ]; then
echo " " | ${MAIL_BIN} -f `hostname`@139.com -h smtp.api.localdomain -s "${MAIL_IP}:Succes Innobackupex backup" ${MAIL_LIST} < ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
else
echo " " | ${MAIL_BIN} -f `hostname`@139.com -h smtp.api.localdomain -s "${MAIL_IP}:Error Innobackupex backup" ${MAIL_LIST} < ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
fi
}
# Step 1: if slave status is ok,then backup the databases,else send error information and exit
$MYSQL -u$BACKUP_USER -h$BACKUP_HOST -p$BACKUP_PASSWD -Bse"show slave status \G">${WORKPATH}/slave_status.txt
SLAVE_IO_RUNNING_STATUS=`cat ${WORKPATH}/slave_status.txt|grep Slave_IO_Running|cut -d: -f2|sed s/[[:space:]]//g`
SLAVE_SQL_RUNNING_STATUS=`cat ${WORKPATH}/slave_status.txt|grep Slave_SQL_Running|cut -d: -f2|sed s/[[:space:]]//g`
if [ ${SLAVE_IO_RUNNING_STATUS} != Yes ]; then
echo "SLAVE_IO_RUNNING_STATUS is not Yes">${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
my_sentmail 0
exit 0
fi
if [ ${SLAVE_SQL_RUNNING_STATUS} != Yes ]; then
echo "SLAVE_SQL_RUNNING_STATUS is not Yes">${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
my_sentmail 0
exit 0
fi
# Step 2: To check the backup work directory room
# if nfs then $1 and $4
SPACE_ROOM_CK=`df -k | grep "$BASEDIR" | awk '{print $2}'`
SPACE_USED_RATE=`df -k | grep "$BASEDIR" | awk '{print $5}' |awk -F% '{print $1}'`
if [ ${SPACE_USED_RATE} -lt ${SPACE_RATE} ] && [ ${SPACE_ROOM_CK} -gt ${SPACE_ROOM} ]
then
echo "There have enough room for backup,let goto backup our database now" >> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
else
echo "There have not enough room for our backup work,sadly to heard that" >> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
echo -e "The backup task fail cause for there have not enough space room for backup on directory \nDatabase's IP is ${BACKUP_HOST}" > ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
my_sentmail 0
exit 0
fi
##Step 3:rm dmp file before 2 copys
cd $WORKPATH/$1
keepday=`ls -l|grep MYSQLBACKUP|wc -l`
if [ $keepday -gt 1 ]
then
rm -fr `ls -lt|grep MYSQLBACKUP|tail -n 1|awk '{print $9}'`
fi
##Step 4:make dir
cd $WORKPATH/$1
TMPDIR="MYSQLBACKUP"`date '+%Y%m%d'`
if [ ! -f ${TMPDIR} ]
then
mkdir ${TMPDIR}
fi
#Step 5:to backup
cd $TMPDIR
${INNOBACKUPEX} --user=${BACKUP_USER} --password=${BACKUP_PASSWD} --defaults-file=${DEFAULTS_FILE} --socket=${SOCKET} $WORKPATH/$1/${TMPDIR}/ 2>$WORKPATH/log/$1_${DATE_VAR}.log
# echo The success info to the send mail information file
echo `date '+%Y%m%d%H%M'` > ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
echo "Today backup success. " >> ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
echo `hostname`" for databases:"${ALL_DATABASES}>> ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
echo "Database's IP is ${BACKUP_HOST}">> ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
echo `date '+%Y%m%d%H%M'` >> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
echo "Today backup success! " >> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
echo `hostname`" for databases:"${ALL_DATABASES} >> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
echo "Database's IP is ${BACKUP_HOST}">> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
my_sentmail 1
exit 0
##set environment##
. ~/.bash_profile
BASEDIR="/data_bak"
SPACE_RATE=95 #space rate 95
SPACE_ROOM=10485760 #10GB
WORKPATH=/data_bak/mysqlbackup/percona
DATETIME=`date '+%Y%m%d%H%M'`
INNOBACKUPEX="/usr/bin/innobackupex-1.5.1"
MYSQL="/home/mysqlapp/product/bin/mysql"
BACKUP_USER="root"
BACKUP_PASSWD="******"
BACKUP_HOST="localhost"
BACKUP_PORT="3306"
DEFAULTS_FILE="/home/mysqlapp/config/my.cnf"
SOCKET="/home/mysqlapp/dbdata/mysqld.sock"
DATE_VAR=`date +%F_%H-%M-%S`
MAIL_LIST="xianyezhao@richinfo.cn"
MAIL_BIN="/home/crond/bsmtp"
MAIL_IP="*****"
#sent mail:0 error backup; 1 success backup
my_sentmail()
{
if [ $1 == 1 ]; then
echo " " | ${MAIL_BIN} -f `hostname`@139.com -h smtp.api.localdomain -s "${MAIL_IP}:Succes Innobackupex backup" ${MAIL_LIST} < ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
else
echo " " | ${MAIL_BIN} -f `hostname`@139.com -h smtp.api.localdomain -s "${MAIL_IP}:Error Innobackupex backup" ${MAIL_LIST} < ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
fi
}
# Step 1: if slave status is ok,then backup the databases,else send error information and exit
$MYSQL -u$BACKUP_USER -h$BACKUP_HOST -p$BACKUP_PASSWD -Bse"show slave status \G">${WORKPATH}/slave_status.txt
SLAVE_IO_RUNNING_STATUS=`cat ${WORKPATH}/slave_status.txt|grep Slave_IO_Running|cut -d: -f2|sed s/[[:space:]]//g`
SLAVE_SQL_RUNNING_STATUS=`cat ${WORKPATH}/slave_status.txt|grep Slave_SQL_Running|cut -d: -f2|sed s/[[:space:]]//g`
if [ ${SLAVE_IO_RUNNING_STATUS} != Yes ]; then
echo "SLAVE_IO_RUNNING_STATUS is not Yes">${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
my_sentmail 0
exit 0
fi
if [ ${SLAVE_SQL_RUNNING_STATUS} != Yes ]; then
echo "SLAVE_SQL_RUNNING_STATUS is not Yes">${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
my_sentmail 0
exit 0
fi
# Step 2: To check the backup work directory room
# if nfs then $1 and $4
SPACE_ROOM_CK=`df -k | grep "$BASEDIR" | awk '{print $2}'`
SPACE_USED_RATE=`df -k | grep "$BASEDIR" | awk '{print $5}' |awk -F% '{print $1}'`
if [ ${SPACE_USED_RATE} -lt ${SPACE_RATE} ] && [ ${SPACE_ROOM_CK} -gt ${SPACE_ROOM} ]
then
echo "There have enough room for backup,let goto backup our database now" >> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
else
echo "There have not enough room for our backup work,sadly to heard that" >> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
echo -e "The backup task fail cause for there have not enough space room for backup on directory \nDatabase's IP is ${BACKUP_HOST}" > ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
my_sentmail 0
exit 0
fi
##Step 3:rm dmp file before 2 copys
cd $WORKPATH/$1
keepday=`ls -l|grep MYSQLBACKUP|wc -l`
if [ $keepday -gt 1 ]
then
rm -fr `ls -lt|grep MYSQLBACKUP|tail -n 1|awk '{print $9}'`
fi
##Step 4:make dir
cd $WORKPATH/$1
TMPDIR="MYSQLBACKUP"`date '+%Y%m%d'`
if [ ! -f ${TMPDIR} ]
then
mkdir ${TMPDIR}
fi
#Step 5:to backup
cd $TMPDIR
${INNOBACKUPEX} --user=${BACKUP_USER} --password=${BACKUP_PASSWD} --defaults-file=${DEFAULTS_FILE} --socket=${SOCKET} $WORKPATH/$1/${TMPDIR}/ 2>$WORKPATH/log/$1_${DATE_VAR}.log
# echo The success info to the send mail information file
echo `date '+%Y%m%d%H%M'` > ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
echo "Today backup success. " >> ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
echo `hostname`" for databases:"${ALL_DATABASES}>> ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
echo "Database's IP is ${BACKUP_HOST}">> ${WORKPATH}/maillog/mail_dba_${WORKDATE}.log
echo `date '+%Y%m%d%H%M'` >> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
echo "Today backup success! " >> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
echo `hostname`" for databases:"${ALL_DATABASES} >> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
echo "Database's IP is ${BACKUP_HOST}">> ${WORKPATH}/log/${BACKUP_FILE_NAME}_$WORKDATE.log
my_sentmail 1
exit 0
备份
脚本
主从
功能
邮件
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全私人风险行业
怎么看网络安全等级
西安双路机架服务器什么价格
网络安全维护多少钱
acs服务器管理端口
新乡市美新网络技术有限公司
嘉定区口碑好的软件开发销售方法
58分钟网络安全宣传片
自建数据库
accsee数据库时间设置
苹果电话无法连接到服务器
紫光展锐ai软件开发工程师
网络安全智能
新罗区韦特网络技术服务部
戴尔r620服务器开启显卡
网络安全与保密协议 道客
青岛dns服务器地址
新华社多媒体数据库简介
网络技术核心同步
截取指定内容的数据库
有网络安全培训机构的大厂
定远直销软件开发技术哪家好
视频转英文视频软件开发
东土串口服务器读取bcd吗
网络安全宣传月总结
建立安全风险数据库的意义
新泰市网络安全会议
北京网络安全兼职
通讯录管理数据库设计
中软邯郸软件开发有限公司