Shell sharing of ftp backup server data integrity check and SMS warning

Source: Internet
Author: User

This script checks the data integrity of remote backup to the ftp server and whether ftp is sent to the server, if the ftp server is not backed up in time, the script will trigger the SMS alarm function module to generate an SMS alarm. Finally, due to the limited space on the ftp server, the author has developed a policy for deleting data 90 days ago after soliciting relevant personnel, and has also implemented this function in the script. This script is now posted for your reference. #! /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
}

# Senderror 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 ---------------
# Checking lock files
Logwriter "backup check begin"
GetLock
If [$? = 0]; then
# Check whether the file exists on the current day
Getlastfile/eip_backup/autobk/yourdb/mysql yourdata tgz
If [$? ! = 0]; then
Logwriter "yourdb not update! "
# Send alert SMS
SendSmsToAdmin "yourapp"
Fi
Logwriter "yourappcheck over ."
# Clean up backup data 90 days ago
Find/eip_backup/autobk/yourdb/mysql-name "yourdb *. tgz"-ctime + 90-print-exec rm {}\;
Logwriter "delete yourdb file over ."
Logwriter "backup check over"

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.