MySQL Forums
Forum List  »  General

Linux script - Is mysql coming down for backups?
Posted by: Phil Williams
Date: April 06, 2006 04:30PM

1. Assumes mysql is being shutdown nightly and a file system backup occurs.
2. This script emails if the socket file is more than 1440 minutes old which means the shutdown is not working correctly.

#!/bin/sh
# File Name :bkupck.sh
# Description :This script can be used to tell if mysql instances are being backed up.
# Author :Phil Williams
# Version :1.0
# Released :
# Execution :${TOOLS}/bin/bkupck.sh <instancename>
# Company :
# Date :12/10/05
# Parameters :$1=dinstanename>
# Calls :${HOME}/${SERVERNAME}.env --Setting environment variables
# Revision History:
#
###############################################################################
echo "Starting ${SERVERNAME} bkupck.sh..`date`.."
DATE_STAMP="`date '+%b%d%y:%H:%M:%S'`"

# ========================
# Pager/Mail notifications
# ========================

notify_status()
{
for Email in `echo "${EMAILID}"`
do
echo -e "From: MySql Server\nTo:${Email}\nSubject: ${SUBJECT}\n\n${MSG}" | /usr/sbin/sendmail ${Email}
done
}

# =========================
# Validate input parameters
# =========================
if [ $# -eq 1 ]; then
SERVERNAME=$1
else
echo "Usage: `basename $0` <SERVERNAME>"
exit 1
fi

# ==========================
# Check for environment file
# ==========================
if [ ! -f ${HOME}/${SERVERNAME}.env ]; then
echo "Missing ${HOME}/${SERVERNAME}.env file.."
exit 2
else
. ${HOME}/${SERVERNAME}.env
fi

# ===============================================
# Check for SOCKET file being more than 1 day old
# ===============================================
SOCK=`echo ${SOCKET} |awk -F"/" '{print $5}'`
echo ${SOCK}

cd ${HOME}
BKUP=`find -type s -name ${SOCK} -mmin +1440`
echo ${BKUP}

if [ -n "${BKUP}" ]; then
MSG="MySQL is not being brought down for backup."
SUBJECT="Failed: MySQL cold backup. Hostname: `hostname` MySQL Instance: ${SERVERNAME} at `date`"
notify_status
fi

echo "End ${SERVERNAME} bkupck.sh..`date`.."
######################################################################
# End of bkupck.sh
######################################################################

#!/bin/sh
# File Name :mysqld1.env
# Description :Setting environment variables
# Author :Phil Williams
# Version :1.0
# Released :
# Execution :
# company :
# date :11/22/05
# parameters :
# Calls :
# Revision History:
# Version Details of Change
# ------- ------- -- ------
#
#----------------------------------------------------------------
PATH=/usr/kerberos/bin:/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:/var/lib/mysql/bin:/app/mysql/admin/TOOLS/bin
export HOME=/var/lib/mysql
export TOOLS=/var/lib/mysql/admin/TOOLS
export INSTANCE_NAME=mysqld1
export DUMPDIR=/app1/mysql/mysqldump
export SOCKET=/var/lib/mysql/mysql.sock1
export DAYS_2_KEEP=7
export EMAIL=Y
export PAGE_ON_FAIL=N
export EMAILID=""
#----------------------------------------------------------------------------
# End of mysqld1.env
#----------------------------------------------------------------------------

Options: ReplyQuote


Subject
Written By
Posted
Linux script - Is mysql coming down for backups?
April 06, 2006 04:30PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.