MySQL backup script and backup failure alarm

Source: Internet
Author: User
Tags mysql backup

[[email protected] myfile]# cat mysqlback_zabbix.sh #!/bin/bashuser=rootdb=zabbix# password=123456server=172.16.9.129dir_home=/vol/myfile/mysql_$serverlog_file= $DIR _home/logs/mysqlback.logif  [ ! -d  $DIR _home ];then mkdir  $DIR _home ;fiif [ ! -d   $DIR _home/logs ];then mkdir  $DIR _home/logs ;fidate= ' date +%f ' echo  ' ******* begin********** '  >> $LOG _filedate >> $LOG _file# Automatically delete backup data two days ago date_two_ago= ' date -d   ' 2 days ago '  +%f ' if [ -d  $DIR _home/$DATE _two_ago ] ;then   rm -rf  $DIR _home/$DATE _two_ago >> $LOG _file 2>&1  if [  $? == 0 ];then         echo  "$DIR _home/ $DATE _two_ago removed successfully! " >>  $LOG _file  else         echo  "$DIR _home/$DATE _two_ago Delete failed! " >>  $LOG _file  fifi# start backing up file_name= $DIR _home/$DATEif  [ ! -d $ file_name ];then mkdir  $FILE _name ;fimysqldump -u$user  $DB  >> $LOG _ file 2>&1 > $FILE _name/$DB .sql if [ $? == 0 ];then         echo  "* * $DB * * Backup complete! ">> $LOG _file  else         #失败邮件报警          content=$ (cat  $LOG _file | tail -2 | grep  mysqldump)         /usr/local/zabbix/share/zabbix/alertscripts/ sendmail.sh [email protected]  "Mysqldump error"   "$CONTENT"  fiecho  ' ******** **end********** '  >> $LOG _file

Senfmail.sh content:

[Email protected] myfile]# cat/usr/local/zabbix/share/zabbix/alertscripts/sendmail.sh#!/bin/bash# $ sendmail address# $ sendmail subject# $ content[email protected]send_mail=/usr/local/zabbix/share/zabbix/alertscripts/ Sendemail-v1.56/sendemailserver_mail=mail.benguo.cn$send_mail-f $sender-T "$"-S $server _mail-u "$" m "$ $" >> /dev/null

SendMail:sendemail-v1.56.tar.gz


Add to the scheduled task:

[Root[email protected] myfile]# crontab-e 1 * */vol/myfile/mysqlback_zabbix.sh #每天的1点1分自动执行备份脚本


MySQL backup script and backup failure alarm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.