#Shell script for Netezza Full Backup on Puredata
##Full database Backup crontab entry
30 15 * * 1 /scripts/NZfullbackup.sh PCTGDM > /export/home/nz/scripts/log/NZfullbackup.log 2>&1
##Full database Backup crontab entry
30 15 * * 1 /scripts/NZfullbackup.sh PCTGDM > /export/home/nz/scripts/log/NZfullbackup.log 2>&1
####################################################################
#!/bin/sh
##Pass Database name with space
cd /export/home/nz
. ~/.bashrc
export PATH=/nz/kit/bin:/nz/kit/sbin:/nz/kit/bin/adm:/bin:/usr/bin:/usr/local/bin:.:/nz/support/bin
email_list="NZRed@gmail.com,GCIT-PHXNOC@gmail.com"
DBA="NZyellow@gmail.com"
echo "Please call DBA on call, If It's not acknowledged by DBA" > /tmp/massage.log
HOST=`hostname`
if [ $# > 0 ]; then
for i in "$@"
do
DBNAME=$(nzsql -l|grep -w $i |awk '{ print $i}'|cut -d '|' -f1)
if [ $i = $DBNAME ]; then
DBNAME=$i
BKTP=FULL
DB_TYPE=PROD
LOG_DIR=/export/home/nz/scripts/log
LOG=$LOG_DIR/$i_backup_`hostname`_`date +%y%m%d%H%M%S`.log
BKP_LOG_DIR=/nz/kit/log/backupsvr/
echo "Starting Full backup of Database $DBNAME" >$LOG
#######Backup
NOW=$(date +"%Y-%m-%d")
nzbackup -u admin -db $DBNAME -connector netbackup -connectorArgs "DATASTORE_SERVER=edp-nbu-120-ap:DATASTORE_POLICY=phx_netezza" -streams 8 -v >>$LOG
if [ $? -ne 0 ]; then
cat /tmp/massage.log | mailx -s "FAILED:$DB_TYPE NZ $DBNAME $BKTP Database Backup on $HOST " -a $LOG $email_list
else
BKPSTS=$(nzsql -qc "SELECT status FROM _v_backup_history WHERE optype='${BKTP}' AND dbname = '${DBNAME}' AND starttime = (SELECT MAX(starttime) FROM _v_backup_history where OPTYPE='${BKTP}' and DBNAME = '${DBNAME}');")
BKPLOG=$(nzsql -qc "SELECT logfile FROM _v_backup_history WHERE optype='${BKTP}' AND dbname = '${DBNAME}' AND starttime = (SELECT MAX(starttime) FROM _v_backup_history where OPTYPE='${BKTP}' and DBNAME = '${DBNAME}');")
STATUS=`echo $BKPSTS|cut -d " " -f3`
LOGFILE=`echo $BKPLOG|cut -d " " -f3`
cd $BKP_LOG_DIR
BKP_DT=`echo $LOGFILE|cut -d "." -f3`
echo $BKP_DT
if [ $BKP_DT = $NOW ] && [ $STATUS = "COMPLETED" ]; then
#cat $BKP_LOG_DIR/$LOGFILE | mailx -s "SUCCESS:$DB_TYPE NZ $DBNAME $BKTP Database Backup on $HOST " $email_list
echo "Backup Success"
else
cat /tmp/massage.log | mailx -s "FAILED:$DB_TYPE NZ $DBNAME FULL Database Backup on $HOST " -a $BKP_LOG_DIR/$LOGFILE $email_list
fi
fi
else
echo "$i Database does not exist on $HOST"| mailx -s "Notification:$DB_TYPE NZ $i Database Backup failed on $HOST " $DBA
fi
done
else
echo "Please specify database name " >>$LOG
exit 1;
fi
No comments:
Post a Comment