該腳本實現了對遠程備份到ftp服務器的數據完整性及是否ftp到該服務器進行了檢查,若是沒有及時備份到該ftp服務器則腳本會觸發短信告警功能模塊實現短信的告警,最後因爲ftp服務器的空間有限,筆者在徵求相關人員已經後製定了90天以前的數據進行刪除的策略並在腳本中也實現了該功能。現將該腳本貼出以供你們學習參考。mysql
#!/usr/bin/kshsql
#---------------------------------------------------------服務器
# scriptname:app
# mon the data backup學習
# version:server
# 1.2ip
# description:get
# - if you have "/opt/mon/backup/my.lock",the monitor is unavailability ;it
# - if find service error ,send message to admin.io
# method:
# author:
# create by fengzhanhai
# notes:
# - the return variant is correct equal 0,error equal 1.
#---------------------------------------------------------
#script conf---------------------------------------------
Mon_Path="/backup/autobk/mon"
Mon_log="$Mon_Path/backup.log"
SMS_Server="your sms ip or fetion robot"
SMS_Send="$Mon_Path/sendsms"
Admin_Mobile="$Mon_Path/youmobilelist"
SMS_From=`hostname`
SMS_Header="Your-Mysql--DataBackup-"
Service_IP="your ftp server"
#check the lock file------------------------------------
getLock()
{
if [ -f "$Mon_Path/$Service_Name.lock" ];then
return 1
else
return 0
fi
}
#writer the message to log--------------------------
logwriter()
{
if [ ! -d `dirname $Mon_log` ]; then
mkdir -p `dirname $Mon_log`
fi
echo `date "+%Y-%m-%d %H:%M:%S"` : $1 >> $Mon_log
}
#send error sms to admin---------------------
sendSmsToAdmin()
{
CurTime=`date "+%Y-%m-%d %H:%M:%S"`
if [ $# -eq 1 ]; then
if [ ! -z "$1" ];then
tmpTime=`date "+%Y%m%d%H%M%S"`
for mobile in `cat $Admin_Mobile`
do
$SMS_Send -h $SMS_Server $mobile "$SMS_Header$1 not update-$tmpTime-$SMS_From"
done
fi
else
logwriter "call sendSmsToAdmin argus error"
fi
}
#check the lock file------------------------------------
getlastfile()
{
find $1 -name "$2`date "+%Y%m%d"`*.$3"|grep $2
if [ $? = 0 ];then
return 0
else
return 1
fi
}
# main ---------------
#檢查鎖文件
logwriter "backup check begin"
getLock
if [ $? = 0 ];then
#檢查當日文件是否存在
getlastfile /eip_backup/autobk/yourdb/mysql yourdata tgz
if [ $? != 0 ];then
logwriter "yourdb not update!"
#發送告警短信
sendSmsToAdmin "yourapp"
fi
logwriter "yourapp check over."
#清理90天前的備份數據
find /eip_backup/autobk/yourdb/mysql -name "yourdb*.tgz" -ctime +90 -print -exec rm {} \;
logwriter "delete yourdb file over."
logwriter "backup check over"