Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5442591
  • 博文数量: 348
  • 博客积分: 2173
  • 博客等级: 上尉
  • 技术积分: 7900
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-24 17:26
个人简介

雄关漫道真如铁,而今迈步从头越。

文章存档

2022年(4)

2020年(6)

2019年(2)

2018年(2)

2017年(34)

2016年(49)

2015年(53)

2014年(47)

2013年(72)

2012年(79)

分类: 系统运维

2012-07-13 13:55:19

该脚本实现了对远程备份到ftp服务器的数据完整性及是否ftp到该服务器进行了检查,如果没有及时备份到该ftp服务器则脚本会触发短信告警功能模块实现短信的告警,最后由于ftp服务器的空间有限,笔者在征求相关人员已经后制定了90天之前的数据进行删除的策略并在脚本中也实现了该功能。现将该脚本贴出以供大家学习参考。

#!/usr/bin/ksh

#---------------------------------------------------------

# scriptname: 

#       mon the data backup

# version:

#       1.2

# description: 

#       - if you have "/opt/mon/backup/my.lock",the monitor is unavailability ;

#       - if find service error ,send message to admin.      

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

 

阅读(5607) | 评论(3) | 转发(6) |
给主人留下些什么吧!~~

fengzhanhai2012-08-24 08:34:31

xdsnet: 为什么不选用一些自动备份体系,可能比直接用ftp效能高?.....
如果你们公司的服务器比较多而且恰好你维护的系统是外围系统或者非关键系统你就知道为什么需要用到脚本了,大型公司大多都有自己的企业级备份服务软体如legato等但是他们是有license限制的而且维护、使用成本高昂。那么作为一个运维工程师这个时候你就要做出抉择和发挥你的作用了。呵呵

fengzhanhai2012-08-24 08:34:19

如果你们公司的服务器比较多而且恰好你维护的系统是外围系统或者非关键系统你就知道为什么需要用到脚本了,大型公司大多都有自己的企业级备份服务软体如legato等但是他们是有license限制的而且维护、使用成本高昂。那么作为一个运维工程师这个时候你就要做出抉择和发挥你的作用了。呵呵

xdsnet2012-08-23 17:40:01

为什么不选用一些自动备份体系,可能比直接用ftp效能高?