检查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脚本的更多相关文章
- zabbix 利用python脚本实现短信告警
一.编写脚本 cd /usr/local/zabbix-4.0.3/share/zabbix/alertscripts vi zabbix_sms.py 内容如下: #!/usr/bin/python ...
- zabbix系列之十——添加短信告警
zabbix添加短信告警 1.查看zabbix-server脚本存放路径: [root@GYQ-Prod-Zabbix ~]# grep AlertScriptsPath /etc/zabbix/za ...
- zabbix配置短信告警
zabbix版本:3.0.7 短信服务商:云片网 首先在云片网添加相应签名和模板 参照格式 签名:xxx告警 模板: [xxx告警]故障:#status# 服务器:#host# 发生:#trigger ...
- zabbix3调用接口发送短信告警
一.需求 之前使用的邮件告警,由于经常会忽略邮件,所以有时候告警查看的并不及时,所以增加短信告警的,以便及时处理. 二.zabbix-server端的配置 # 需要在zabbix-server端打开A ...
- Android备份和添加短信
手机发送成功的,没有成功的,接受的短信都存放在手机自带的数据库中. 现在想要备份一下这个短信,需要访问这个数据库,然后查询所有的短信.就需要内容提供者(短信). 首先要找到内容提供者的uri.
- prometheus grafana graylog 钉钉告警 短信告警 电话告警系统 PrometheusAlert
PrometheusAlert 简介 PrometheusAlert是开源的运维告警中心消息转发系统,支持主流的监控系统Prometheus,日志系统Graylog和数据可视化系统Grafana发出的 ...
- k8s全方位监控 -prometheus实现短信告警接口编写(python)
1.prometheus短信告警接口实现(python)源码如下: import subprocess from flask import Flask from flask import reques ...
- android101 获取、备份、插入短信
package com.itheima.getsms; import java.io.File; import java.io.FileNotFoundException; import java.i ...
- zabbix4.0短信告警配置
#!/usr/bin/env python3 import requests import sys #http://utf8.api.smschinese.cn/?Uid=USERNAME&K ...
随机推荐
- android 处理图片之--bitmap处理
-2.从资源中获得bitmap Resources res=getResources(); Bitmap bmp=BitmapFactory.decodeResource(res, R.drawabl ...
- 【面试虐菜】—— MongoDB知识整理
为什么我们要使用MongoDB? 特点: 高性能.易部署.易使用,存储数据非常方便.主要功能特性有: 面向集合存储,易存储对象类型的数据. 模式自由. 支持动态查询. 支持完全索引,包含内部对象. 支 ...
- linux jmail乱码
在Windows 里面,标题和内容都正常, 在linux里面,--- 1.字符串 more /etc/sysconfig/i18n export LANG=en_US.UTF-8 ====默认是e ...
- cocos2d-x设计模式发掘之五:防御式编程模式
http://www.ityran.com/archives/2105 本文由子龙山人原创,泰然授权转载,转载请注明出处并通知子龙山人! 声明:防御式编程是提高程序代码质量的一种手段,它不能算是真正意 ...
- 闲话shuffle(洗牌)算法
工作中经常会用到洗牌算法,看到这篇文章不错,原文摘自:http://www.atatech.org/article/detail/11821/928 作者:子仲 场景 洗牌算法的应用场景其实很多 ...
- Markdown 添加 Latex 数学公式
添加公式的方法 Latex 数学公式语法 添加公式的方法 行内公式 $行内公式$ 行间公式 $$行间公式$$ Latex 数学公式语法 角标(上下标) 上标命令^{} 下标命令_{} 上下标命令用来放 ...
- Import user's Environment path into Linux cron task
How to use "cron" to create scheduled task Minimum time cycle: 1 minute Use crontab -e edi ...
- AWS RDS 使用笔记
创建VPC安全组 添加VPC子网 创建RDS子网组 创建RDS参数组 创建MySQL实例 查看RDS终端节点 使用 MySQL 监视器与数据库实例上的数据库连接 安装mysql client $ su ...
- Smokeping 监控部署及配置
安装参见: https://github.com/oetiker/SmokePing/blob/master/doc/smokeping_install.pod 1 Smokeping *** Gen ...
- Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面
现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下. 1.跳转到拨号界面,代码如下: 1)直接拨打 Intent intentPhone = new Intent ...