发布:thebaby   来源:net     【  
检查ftp备份数据完整性及短信告警的shell,有需要的朋友可以参考下。
该脚本实现如下的功能:

对远程备份到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"

检查ftp备份数据完整性及短信告警的shell脚本的更多相关文章

  1. zabbix 利用python脚本实现短信告警

    一.编写脚本 cd /usr/local/zabbix-4.0.3/share/zabbix/alertscripts vi zabbix_sms.py 内容如下: #!/usr/bin/python ...

  2. zabbix系列之十——添加短信告警

    zabbix添加短信告警 1.查看zabbix-server脚本存放路径: [root@GYQ-Prod-Zabbix ~]# grep AlertScriptsPath /etc/zabbix/za ...

  3. zabbix配置短信告警

    zabbix版本:3.0.7 短信服务商:云片网 首先在云片网添加相应签名和模板 参照格式 签名:xxx告警 模板: [xxx告警]故障:#status# 服务器:#host# 发生:#trigger ...

  4. zabbix3调用接口发送短信告警

    一.需求 之前使用的邮件告警,由于经常会忽略邮件,所以有时候告警查看的并不及时,所以增加短信告警的,以便及时处理. 二.zabbix-server端的配置 # 需要在zabbix-server端打开A ...

  5. Android备份和添加短信

    手机发送成功的,没有成功的,接受的短信都存放在手机自带的数据库中. 现在想要备份一下这个短信,需要访问这个数据库,然后查询所有的短信.就需要内容提供者(短信). 首先要找到内容提供者的uri.

  6. prometheus grafana graylog 钉钉告警 短信告警 电话告警系统 PrometheusAlert

    PrometheusAlert 简介 PrometheusAlert是开源的运维告警中心消息转发系统,支持主流的监控系统Prometheus,日志系统Graylog和数据可视化系统Grafana发出的 ...

  7. k8s全方位监控 -prometheus实现短信告警接口编写(python)

    1.prometheus短信告警接口实现(python)源码如下: import subprocess from flask import Flask from flask import reques ...

  8. android101 获取、备份、插入短信

    package com.itheima.getsms; import java.io.File; import java.io.FileNotFoundException; import java.i ...

  9. zabbix4.0短信告警配置

    #!/usr/bin/env python3 import requests import sys #http://utf8.api.smschinese.cn/?Uid=USERNAME&K ...

随机推荐

  1. GPUImage的简单使用

    GPUImage 是一个开源的图像处理库,提供了非常多的滤镜效果来加工图片.GPUImage 并不像一般的第三方库可以直接拖入到工程中使用,而是需要先在本地编译,然后将编译后的文件拖入到工程中使用.配 ...

  2. bootstrap-table对前台页面表格的支持

    1.bootstrap-table是在bootstrap的基础上面做了一些封装,所以在使用bootstrap-table之前要导入的js和css有 1)基本的还是jQuery <script t ...

  3. Filter过滤器(1)

    Filter也称之为过滤器,它是Servlet技术中比较激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态图片文件或静态 ht ...

  4. Oracle--SQL Developer创建连接及使用

    安装好Oracle之后,有几种方式可以来管理Oracle中的数据库,首先就是登陆网页版的界面:https://localhost:1158/em,这种方式管理的东西太多,使用起来有点不方便,第二种方式 ...

  5. UVa 497 - Strategic Defense Initiative

    题目:最大上升子序列.输出一组解. 分析:dp,LIS.数据较小 O(n^2)算法就可以. 设以第i个数字作为最大上升子序列中的最后一个数的长度为 f(i),则有转移方程: f(i)= max(f(j ...

  6. CardsTube/YouTubePlaylist

    CardsTube https://github.com/DesarrolloAntonio/CardsTube YouTubePlaylist https://github.com/akoscz/Y ...

  7. iOS开发技巧(系列十八:扩展UIColor,支持十六进制颜色设置)

    新建一个Category,命名为UIColor+Hex,表示UIColor支持十六进制Hex颜色设置. UIColor+Hex.h文件, #import <UIKit/UIKit.h> # ...

  8. How to save/read file on different platforms

    You can use standard c functions, such as fopen, fwrite, to save and read file on different platform ...

  9. 【转】cocos2d-x获取系统时间——2013-08-25 10

    欢迎转载,本帖地址:http://blog.csdn.net/jinjian2009/article/details/9449585 之前使用过cocos2d-x获取系统时间,毫秒级的 long ge ...

  10. Android(java)学习笔记157:使用Dexdump等工具进行反编译

    使用Dex等工具进行反编译步骤: (1)首先找到Android软件安装包中的class.dex,把APK文件改名为".zip",然后解压缩其中的class.dex文件,这是Java ...