# 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
# 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