cross clmn

Thursday 26 May 2016

Check Environment details on IBM Netezza



Check Environment details on IBM Netezza 

HPF version: 

cat /nzlocal/scripts/version.txt    

MODEL 

cat /nzlocal/scripts/model                   

FDT version :      
                                               
head -2 /opt/Netezza/FW/PSeries/version.txt                          
head -2 /opt/nz/fdt/version.txt    
                               
RedHat version:                                                      
lsb_release -i -r    
                                             
As nz user:                                                          
NPS version:
nzrev                          
                        
Current System Stats: nzstats  
Hardware stataus  
nzhw -issues
nzds -issues
                             
As root user:                                                        
uname -n        


model of the system                                                      
dmidecode -t 1  

Callhome                                                
cat /nz/data/config/callHome.txt   

Thursday 19 May 2016

Netezza Database refresh from prod to Dev --- Incremental Refresh nzbackup nzrestore

Netezza Database refresh from prod to Dev --- Incremental Refresh nzbackup nzrestore

1. Once We have done with full backup and restore, Then we may start incremental backup and restore .

Incremental backup 
crontab Entry:-
1 * * * * /export/home/nz/scripts/refresh/incr_backup_refresh.sh PMACDW      > /dev/null 2>&1

######################Incremental Backup shell script #######################
#!/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="EDW_Support@gmail.com"
DBA="NZRed@gmail.com,EDW_Support@gmail.com"
echo "Please call DBA , If It's not acknowledged by DBA" > /tmp/massage.log
HOST=`hostname`
if [ $# > 0 ]; then
    i=$1
    DBNAME=$(nzsql -l|grep -w $i |awk '{ print $i}'|cut -d '|' -f1|cut -d " " -f2)
    if [ $i = "$DBNAME" ]; then
                DBNAME=$i
                DB=$DBNAME
                DB=`echo "${DB,,}"| cut -c 2-`
                BKTP=DIFF
                DB_TYPE=PROD
                LOG_DIR=/export/home/nz/scripts/log
                LOG=$LOG_DIR/$DBNAME_backup_`hostname`_`date +%y%m%d%H%M%S`.log
                BKP_LOG_DIR=/nz/kit/log/backupsvr/
                file1=/nz/$DB/triggers/$DB.done
                file1a=/nz/$DB/triggers/$DB.wip
                file1b=/nz/$DB/triggers/$DB.bkup_done
                file1c=/nz/$DB/triggers/$DB.bkup_aborted
                ########checking logfile status
                if [ -f "$file1" ]; then
                        echo " Initiate incremental backup - trigger file available" > $LOG
                        mv $file1 $file1a
                        echo "incremental  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"  -differential -streams 8 -v  >>$LOG
                        if [ $? -ne 0 ]; then
                                cat /tmp/massage.log | mailx -s "FAILED:Backup(Refresh) NZ  $DBNAME $BKTP Database Backup on  $HOST " -a $LOG $DBA
                                 mv $file1 $file1c
                        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
                                                /bin/touch /dbbackup/refresh_trigger/bnr/.incr_bkups_$DBNAME.done
                                                mv $file1a $file1b
                                        else
                                        cat /tmp/massage.log | mailx -s "FAILED:Backup(Refresh)NZ $DBNAME $BKTP Database Backup on  $HOST " -a $BKP_LOG_DIR/$LOGFILE $DBA
                                        mv $file1a $file1c
                                        fi
                        fi
                        else
                        echo "Triiger file does not exist `date`" > $LOG
                        exit;
                        fi
    else
     echo "$i Database does not exist on $HOST"| mailx -s "Notification:$DB_TYPE  NZ $i  Database Backup failed on  $HOST " $DBA
    fi
else
echo "Please specify database name " >>$LOG
exit 1;

fi


################################################################################
Incremental Restore Script to Refresh 
################################################################################
Crontab Entry 

/export/home/nz/scripts/refresh/incr_restore_refresh.sh PMACDW 

#############################################################################
#!/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="EDW_Support@gmail.com"
DBA="NZRed@gmail.com,EDW_Support@gmail.com"
HOST=`hostname`
if [ $# > 0 ]; then
    i=$1
    DBNAME=$(nzsql -l|grep -w $i |awk '{ print $i}'|cut -d '|' -f1|cut -d " " -f2)
    if [ $i = "$DBNAME" ]; then
                DBNAME=$i
                DB=$DBNAME
                DB=`echo "${DB,,}"`
                BKTP="INCR:REST"
                DB_TYPE=DEV
                LOG_DIR=/export/home/nz/scripts/log
                LOG=$LOG_DIR/$DBNAME_restore_`hostname`_`date +%y%m%d%H%M%S`.log
                RST_LOG_DIR=/nz/kit/log/restoresvr/
               file1=/dbbackup/refresh_trigger/bnr/.incr_bkups_$DBNAME.done
               file1a=/dbbackup/refresh_trigger/bnr/.incr_restore_$DBNAME.wip
               file1b=/dbbackup/refresh_trigger/bnr/incr_restore_$DBNAME.done
               file1c=/export/home/nz/dba/scripts/bnr/.incr_restore_$DBNAME.abort
                ########checking logfile status
                if [ -f "$file1" ]; then
                echo " Initiate incremental restore - trigger file available" >> $LOG
                mv $file1 $file1a
                echo "Starting incremental restore of Database $DBNAME" >>$LOG
                 #######Restore
                NOW=$(date +"%Y-%m-%d")
                nzrestore -db $DBNAME -sourcedb $DBNAME  -connector netbackup -connectorArgs DATASTORE_SERVER=edp-nbu-120-ap  -streams 8 -v  -npshost 7836279-H1 -increment REST -lockdb T >>$LOG
                        if [ $? -ne 0 ]; then
                              echo "FAILED:$BKTP Refresh $DBNAME Database on $HOST "| mailx -s "FAILED:$BKTP Refresh NZ  $DBNAME $BKTP Database Restore on  $HOST " -a $LOG $DBA
                              mv -f $file1a $file1c
                        else
                                RSTSTS=$(nzsql  -qc  "SELECT  status  FROM  _v_Restore_history     WHERE   optype='${BKTP}'    AND     dbname = '${DBNAME}'  AND     starttime = (SELECT MAX(starttime) FROM _v_Restore_history where OPTYPE='${BKTP}' and DBNAME = '${DBNAME}');")
                                RSTLOG=$(nzsql  -qc  "SELECT  logfile  FROM  _v_Restore_history     WHERE   optype='${BKTP}'    AND     dbname = '${DBNAME}'  AND     starttime = (SELECT MAX(starttime) FROM _v_Restore_history where OPTYPE='${BKTP}' and DBNAME = '${DBNAME}');")
                                STATUS=`echo $RSTSTS|cut -d " " -f3`
                                LOGFILE=`echo $RSTLOG|cut -d " " -f3`
                                cd $RST_LOG_DIR
                                RST_DT=`echo $LOGFILE|cut -d "." -f3`
                                echo $RST_DT
                                        if [ $RST_DT = $NOW ] && [ $STATUS = "COMPLETED" ]; then
                                                cat $RST_LOG_DIR/$LOGFILE | mailx -s "SUCCESS:$BKTP Refresh NZ  $DBNAME Database  on  $HOST " $email_list
                                             #   /bin/touch /dbbackup/refresh_trigger/bnr/.full_bkups_$DBNAME.done
                                                mv -f $file1a $file1b
                                        else
                              echo "FAILED:$BKTP Refresh $DBNAME Database on $HOST "| mailx -s "FAILED:$BKTP NZ Refresh $DBNAME Database Restore on  $HOST " -a $RST_LOG_DIR/$LOGFILE $DBA
                                        mv -f $file1a $file1c
                                        fi
                        fi
                        else
                        echo "Triiger file does not exist `date`" > $LOG
                        exit;
                        fi
    else
     echo "$i Database does not exist on $HOST"| mailx -s "Notification:$DB_TYPE  NZ $i  Database Restore failed on  $HOST " $DBA
    fi
else
echo "Please specify database name " >>$LOG
exit 1;
fi

Netezza Database refresh from prod to Dev --- Full Refresh nzbackup nzrestore

1. Using backup scirpt it will take backup of database specified after trigger file found and it will create a trigger file on dev to start restore PMACDW  database.

crontab Entry try every 15 min and wait for trigger file

00,15,30,45 4-10 * * 6 /export/home/nz/scripts/refresh/full_backup_refresh.sh PGCIDWSEC   > /dev/null 2>&1
#############################Full Backup script#################################

#!/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="EDW_Support@gmail.com"
DBA="NZRed@gmail.com,EDW_Support@gmail.com"
echo "Please call DBA , If It's not acknowledged by DBA" > /tmp/massage.log
HOST=`hostname`
if [ $# > 0 ]; then
    i=$1
    DBNAME=$(nzsql -l|grep -w $i |awk '{ print $i}'|cut -d '|' -f1|cut -d " " -f2)
    if [ $i = "$DBNAME" ]; then
                DBNAME=$i
                DB=$DBNAME
                DB=`echo "${DB,,}"| cut -c 2-`
                BKTP=FULL
                DB_TYPE=PROD
                LOG_DIR=/export/home/nz/scripts/log
                LOG=$LOG_DIR/$DBNAME_backup_`hostname`_`date +%y%m%d%H%M%S`.log
                BKP_LOG_DIR=/nz/kit/log/backupsvr/
                file1=/nz/$DB/triggers/$DB.done
                file1a=/nz/$DB/triggers/$DB.wip
                file1b=/nz/$DB/triggers/$DB.bkup_done
                file1c=/nz/$DB/triggers/$DB.bkup_aborted
                ########checking logfile status
                if [ -f "$file1" ]; then
                        echo " Initiate incremental backup - trigger file available" > $LOG
                        mv $file1 $file1a
                        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:Backup(Refresh) NZ  $DBNAME $BKTP Database Backup on  $HOST " -a $LOG $DBA
                                                                mv $file1 $file1c
                        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
                                                /bin/touch /dbbackup/refresh_trigger/bnr/.full_bkups_$DBNAME.done
                                                mv $file1a $file1b
                                        else
                                        cat /tmp/massage.log | mailx -s "FAILED:Backup(Refresh)NZ $DBNAME $BKTP Database Backup on  $HOST " -a $BKP_LOG_DIR/$LOGFILE $DBA
                                        mv $file1a $file1c
                                        fi
                        fi
                        else
                        echo "Triiger file does not exist `date`" > $LOG
                        exit;
                        fi
    else
     echo "$i Database does not exist on $HOST"| mailx -s "Notification:$DB_TYPE  NZ $i  Database Backup failed on  $HOST " $DBA
    fi
else
echo "Please specify database name " >>$LOG
exit 1;
fi


################################################################################
2. After we get the trigger file on dev it will hit Full restore on DEV for PMACDW  database.
crontab 
00,15,30,45 5-11 * * 6 /export/home/nz/scripts/refresh/full_restore_refresh.sh PMACDW >/dev/null 2>&1

###############################Full Restore script ################################
#!/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="EDW_Support@gmail.com"
DBA="NZRed@gmail.com,EDW_Support@gmail.com"
HOST=`hostname`
if [ $# > 0 ]; then
    i=$1
    DBNAME=$(nzsql -l|grep -w $i |awk '{ print $i}'|cut -d '|' -f1|cut -d " " -f2)
    if [ $i = "$DBNAME" ]; then
                DBNAME=$i
                DB=$DBNAME
                DB=`echo "${DB,,}"`
                BKTP=FULL
                DB_TYPE=DEV
                LOG_DIR=/export/home/nz/scripts/log
                LOG=$LOG_DIR/$DBNAME_restore_`hostname`_`date +%y%m%d%H%M%S`.log
                RST_LOG_DIR=/nz/kit/log/restoresvr/
               file1=/dbbackup/refresh_trigger/bnr/.full_bkups_$DBNAME.done
               file1a=/dbbackup/refresh_trigger/bnr/.full_restore_$DBNAME.wip
               file1b=/dbbackup/refresh_trigger/bnr/.full_restore_$DBNAME.done
               file1c=/export/home/nz/dba/scripts/bnr/.full_restore_$DBNAME.abort
                ########checking logfile status
                if [ -f "$file1" ]; then
                ##This is to capture user sessions during LQC full restoration
                nzsession | grep $DBNAME  > /export/home/nz/cap_session
                #cat /export/home/nz/cap_session | mail -s "List of EDW-NTZ-LQC on $DBNAME user session on `date` " $email_list
                #End of user tracing during full restore set2

                # Kill users connected to dbs to be dropped
                for killpid in `nzsession | grep $DBNAME | awk '{print $1}'`; do
                echo "PID killed"
                echo $killpid
                nzsession abort -id ${killpid} -force
                done
                # Drop  database $DBNAME before restoring new ones
                /nz/kit/bin/nzsql < /export/home/nz/dba/scripts/bnr/dropdbs_$DBNAME.sql
                 if [ $? -ne 0 ]; then
                echo "DATABASE $DBNAME DROP COMMAND FAILED CAUSES EXISTING REFRESH,It will try again after 15 min."|mailx -s "FAILED:$BKTP Refresh NZ $DBNAME $BKTP Database Restore on $HOST"  $DBA
                exit;
                else
                 echo "DATABASE DROPPED"
                 fi
                echo " Initiate FULL restore - trigger file available" >> $LOG
                mv $file1 $file1a
                echo "Starting FULL restore of Database $DBNAME" >>$LOG
                 #######Restore
                NOW=$(date +"%Y-%m-%d")
                nzrestore -db $DBNAME -sourcedb $DBNAME  -connector netbackup -connectorArgs DATASTORE_SERVER=edp-nbu-120-ap  -streams 8 -v  -npshost 7836279-H1 -lockdb T >>$LOG
                        if [ $? -ne 0 ]; then
                            echo " FAILED:$BKTP Refresh NZ DB  $DBNAME  on  $HOST"| mailx -s "FAILED:$BKTP Refresh NZ DB $DBNAME  on  $HOST " -a $LOG $DBA
                            mv -f $file1a $file1c
                        else
                                RSTSTS=$(nzsql  -qc  "SELECT  status  FROM  _v_Restore_history     WHERE   optype='${BKTP}'    AND     dbname = '${DBNAME}'  AND     starttime = (SELECT MAX(starttime) FROM _v_Restore_history where OPTYPE='${BKTP}' and DBNAME = '${DBNAME}');")
                                RSTLOG=$(nzsql  -qc  "SELECT  logfile  FROM  _v_Restore_history     WHERE   optype='${BKTP}'    AND     dbname = '${DBNAME}'  AND     starttime = (SELECT MAX(starttime) FROM _v_Restore_history where OPTYPE='${BKTP}' and DBNAME = '${DBNAME}');")
                                STATUS=`echo $RSTSTS|cut -d " " -f3`
                                LOGFILE=`echo $RSTLOG|cut -d " " -f3`
                                cd $RST_LOG_DIR
                                RST_DT=`echo $LOGFILE|cut -d "." -f3`
                                echo $RST_DT
                                   if [ $RST_DT = $NOW ] && [ $STATUS = "COMPLETED" ]; then
                                   cat $RST_LOG_DIR/$LOGFILE | mailx -s "SUCCESS:$BKTP Refresh NZ  $DBNAME Database  on  $HOST " $email_list
                                   #/bin/touch /dbbackup/refresh_trigger/bnr/.full_bkups_$DBNAME.done
                                   mv -f  $file1a $file1b
                                   else
                                   echo "FAILED:$BKTP NZ Refresh DB $DBNAME on  $HOST " | mailx -s "FAILED:$BKTP NZ Refresh DB $DBNAME on  $HOST " -a $RST_LOG_DIR/$LOGFILE $DBA
                                   mv -f $file1a $file1c
                                   fi
                        fi
                        else
                        echo "Triiger file does not exist `date`" > $LOG
                        exit;
                        fi
    else
     echo "$i Database does not exist on $HOST"| mailx -s "Notification:$DB_TYPE  NZ $i  Database Restore failed on  $HOST " $DBA
    fi
else
echo "Please specify database name " >>$LOG
exit 1;
fi

Shell Script Incremental Backup on netezza Puredata IBM nzrestore

#Shell Script Incremental Backup on netezza Puredata IBM

#1* * * * /export/home/nz/scripts/refresh/incr_backup_refresh.sh PMACDW

#!/bin/sh
##Pass Database name with space
email_list="NZRed@gmail.com,GCIT-PHXNOC@gmail.com"
DBA="NZyellow@gmail.com"
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
HOST=`hostname`
echo "Please call DBA on call, If It's not acknowledged by DBA" > /tmp/massage.log
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=DIFF
                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 Incremental  backup of Database $DBNAME on `date +%y%m%d%H%M%S`" >$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" -differential -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 Incremental Database Backup on  $HOST " $email_list
                                                echo "Backup Success"
                                        else
                                        cat /tmp/massage.log | mailx -s "FAILED:$DB_TYPE NZ $DBNAME Incremental 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 Incremental Backup failed on  $HOST " $DBA
    fi
    done
else
echo "Please specify database name " >>$LOG
exit 1;
fi

Netezza Full Backup on Puredata nzbackup

#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
####################################################################
#!/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

Monday 2 May 2016

Shell script to Netezza System status (NPS) IBM Netezza

#Shell script to Netezza System status (NPS) IBM Netezza
#Manish Jaiswal
#!/bin/sh
# =============================================================================
# Netezza  NPS Status
# =============================================================================
# Script configuration - Static values only.
# =============================================================================
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
NPS_STATE=`nzstate | awk '{print $4}' | tr -d "[.']" | tr "[a-z]" "[A-Z]"`
# ------------------------------------------------------------------------
# Make sure the system is online.
# ------------------------------------------------------------------------
if [ "${NPS_STATE}" = "ONLINE" ]
then
   echo "${NPS_STATE}"
        SYSTEMSTATE=0
else
   echo "NPS ${NPS_STATE} OFFLINE During Hostbackup!"
   echo  " NPS is Offline on  $HOST in Current state: [${NPS_STATE}]"|mailx -s "CRITICAL:NZHOSTBACKUP  on  $HOST " $email_list
   exit;
fi

Shell script to Generate Table skew Report on IBM Netezza System(nz_skew).

#Shell script to Generate Table skew  Report  on IBM Netezza System(nz_skew).
#Manish Jaiswal
#!/bin/sh
# =============================================================================
# Netezza Table Skew script
# =============================================================================
# Script configuration - Static values only.
# =============================================================================
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
export email_list="NZGreen@gmail.com,EDW_Support@gmail.com"
#export email_list="manish.jaiswal@gmail.com"
export SCRIPTOUTPUTDIR=/export/home/nz/scripts/MONITOR
export VIPHOSTNAME=EDW-NTZ-001-LQC
export SCRIPTSTART=$(date -d "$1" +"%Y%m%d")
export NZSUPPORT7207BINDIR=/nz/support-IBM_Netezza-7.2.0.7.P1-160122-1638/bin
export RPT_FILE="${SCRIPTOUTPUTDIR}/${VIPHOSTNAME}.skew.${SCRIPTSTART}.txt"
find $SCRIPTOUTPUTDIR/*txt  -mtime +5 -exec rm {} \;

# -----------------------------------------------------------------------------
# Run the nz_skew command and generate report.
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Start the checks.
# -----------------------------------------------------------------------------
echo "Starting table skew check for ${VIPHOSTNAME}"

${NZSUPPORT7207BINDIR}/nz_skew -sort size | grep -v "^ [DPQ]MISC"   > ${RPT_FILE} 2>&1

RetCode=$?

# Check the outcome.
if [ ${RetCode} -eq 0 ]
then
        echo "Successful."
else
        echo "FAILED!"
echo  "Table skew check report generation failure! [${VIPHOSTNAME}]" |mailx -s "Notification:Table skew check report generation failure! [${VIPHOSTNAME}]" $email_list
exit;
fi

echo "Finished table skew check for ${VIPHOSTNAME}"
# -----------------------------------------------------------------------------
# Distribute the table skew check report.
# -----------------------------------------------------------------------------
echo "Distributing table skew report for ${VIPHOSTNAME}"

echo  "Netezza Table Skew Report for  ${VIPHOSTNAME}" |mailx -s "Netezza Table Skew Report for  ${VIPHOSTNAME} " -a ${RPT_FILE} $email_list

# =============================================================================
# Script Completion
# =============================================================================

shell script to Monitor Disk on Netezza IBM system disk_monitor

#shell script to Monitor Disk on Netezza IBM system  disk_monitor
#Manish Jaiswal
#!/bin/sh
# =============================================================================
# Netezza Disk Monitor Template
# =============================================================================
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,EDW_Support@gmail.com"
SCRIPTOUTPUTDIR=/export/home/nz/scripts/MONITOR
VIPHOSTNAME=EDW-NTZ-001-LQC
SCRIPTSTART=$(date -d "$1" +"%Y%m%d")
export NZSUPPORT7207BINDIR=/nz/support-IBM_Netezza-7.2.0.7.P1-160122-1638/bin
export RPT_FILE="${SCRIPTOUTPUTDIR}/${VIPHOSTNAME}.DiskMonitor.${SCRIPTSTART}.txt"
export CLEAN_RPT_FILE="${SCRIPTOUTPUTDIR}/${VIPHOSTNAME}.DiskMonitor.${SCRIPTSTART}.clean.txt"
export ACTIONS_FILE="${SCRIPTOUTPUTDIR}/${VIPHOSTNAME}.DiskMonitor.${SCRIPTSTART}.actions.txt"
find $SCRIPTOUTPUTDIR/*txt  -mtime +5 -exec rm {} \;
# -----------------------------------------------------------------------------
# Start the disk checks.
# -----------------------------------------------------------------------------
echo  "Starting disk monitor for ${VIPHOSTNAME}"

#/nz/support-IBM_Netezza-7.2.0.7.P1-160122-1638/bin/adm/disk_monitor \

${NZSUPPORT7207BINDIR}/adm/disk_monitor   > ${RPT_FILE} 2>&1

RetCode=$?

# Check the outcome.
if [ ${RetCode} -eq 0 ]
then
        echo "Successful."
else
        echo "FAILED!"
        echo  "Disk monitor report generation failure! [${VIPHOSTNAME}]" |mailx -s "Notification:Disk monitor report generation failure! [${VIPHOSTNAME}]" $email_list
fi

echo  "Finished disk monitor for ${VIPHOSTNAME}"
# -----------------------------------------------------------------------------
# Check for actionable items and alert as needed.
# -----------------------------------------------------------------------------

echo "Checking ${VIPHOSTNAME} disk monitor report for actionable items"

# Strip the stderr output from the report.
sed -ne '/^[A-Z]/d;p' "${RPT_FILE}"  | sed -e '/Fewer lines on second insert/d' > ${CLEAN_RPT_FILE}

# Extract the actionable portion of the report.
sed -n '/Actionable/,/^(/p' ${CLEAN_RPT_FILE} > ${ACTIONS_FILE}

# Get the number of actionable items.
ActionableItems=`grep "^(" ${ACTIONS_FILE} | sed 's/[^0-9]*//g'`

# If we dont have any actions to take then we're done.  Otherwise send an alert.
if [ ${ActionableItems} -eq 0 ]
then
echo  "No actions needed"
        #echo  "No actions needed"|mailx -s "Notification:Disk monitor report generation suceed! [${VIPHOSTNAME}]" $email_list
else
        echo "${ActionableItems} actionable items found!"
        echo "Disk monitor report found actionable items! [${VIPHOSTNAME}]"

       echo  "Disk failure Found in [${VIPHOSTNAME}]" |mailx -s "Disk failure Found in [${VIPHOSTNAME}] " -a ${ACTIONS_FILE} $email_list
fi

# =============================================================================
# Script Completion
# =============================================================================

Shell Script to check invalid Views on IBM Netezza System (nz_check_views)

#Shell Script to check invalid  Views on IBM Netezza System
#Manish Jaiswal
#!/bin/sh
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
DBA_email="EDW_Support@gmail.com"
DATE=`date +%Y-%m-%d:%H:%M:%S`
LOG=/export/home/nz/scripts/log/check_invalid_views_lp_$DATE.log
echo "Starting view check on `hostname` " > $LOG
for i in `cat /export/home/nz/scripts/PRD_LP_DB_List.lst`
        do
         echo "Starting view check of Database $i " >> $LOG
         nz_check_views $i >> $LOG
done
echo " Find the NZ View check  Report for `hostname` server in attachment"| mailx -s "`hostname` NZ View check  Report for Netezza  on `date +%y%m%d%H%M%S` " -a $LOG "$DBA_email"

Shell Scripts to Generate Statistics on IBM Netezza System ( nz_genstats) GENERATE EXPRESS STATISTICS

#Shell Scripts to Generate Statistics on IBM Netezza System ( nz_genstats) GENERATE EXPRESS #STATISTICS
#Manish Jaiswal
#!/bin/sh
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
### Database List needed to be analyzed
DB_LIST=$(nzsql -l |awk ' NR > 3'|sed '$d' |awk '{ print $1 }'|sed '$d')
##############
DBA_email="EDW_Support@gmail.com"
DAY=`date '+%a'`
LOG_DIR=/export/home/nz/scripts/log
LOG=$LOG_DIR/analyzed_`hostname`_`date +%y%m%d%H%M%S`.log
###Delete 15 days old log
find $LOG_DIR/*.log  -type f -mtime +15 -exec rm -f {} \; 2> /dev/null
##############################
###Main Function
analyze_db_fn()
{
### Genrate Gather stats  for $DAY listed databses
  for i in `echo $DB_LIST`
           do
           echo "Starting Gather stats of Database $i on `date +%y%m%d%H%M%S` " >> $LOG
  nz_genstats ${i} >> $LOG
  if [ $? -eq 0 ]; then
  echo "Succeeed GENERATE EXPRESS STATISTICS of database $i on `date +%y%m%d%H%M%S` " >> $LOG
  else
  echo "Failure GENERATE EXPRESS STATISTICS of database $i on `date +%y%m%d%H%M%S` " >> $LOG
  fi
   done
echo " Please find GENERATE STATISTICS Report in attachment for `hostname`"| mailx -s " Gather Stats  Report for Netezza $DAY `hostname` server on `date +%y%m%d%H%M%S` " -a $LOG "$DBA_email"
}
##############################
##Call Funtion to Genrate stats
analyze_db_fn
##

Shell Scripts for NZ GROOM on Netezza IBM system

#Shell Scripts  for NZ GROOM on Netezza IBM system
#Manish Jaiswal
#!/bin/sh
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
### Database List needed to be groom
##Big Databases
DB_LIST_WED_SAT=$(nzsql -l |awk ' NR > 3'|sed '$d' |awk '{ print $1 }'|sed '$d'|egrep -E '(PGCIDW|PGCRDW|PMFIDW|PMACDW)')
##small Databases
DB_LIST_SUN=$(nzsql -l |awk ' NR > 3'|sed '$d' |awk '{ print $1 }'|sed '$d'|egrep -v '(PGCIDW|PGCRDW|PMFIDW|PMACDW)')
##############
DBA_email="EDW_Support@gmail.com"
DAY=`date '+%a'`
LOG_DIR=/export/home/nz/scripts/log
LOG=$LOG_DIR/groom_`hostname`_`date +%y%m%d%H%M%S`.log
###Delete 15 days old log
find $LOG_DIR/*.log  -type f -mtime +15 -exec rm -f {} \; 2> /dev/null
##############################
###Main Function
groom_db_fn()
{
### running groom for $DAY listed databses
echo "groom started for `hostname1` " > $LOG
  for i in `echo $GROOM_DB_LIST`
           do
           echo "Starting Groom of Database $i on `date +%y%m%d%H%M%S` " >> $LOG
           Table_name=$(nzsql -A -c "select  objname as table_name from _v_sys_relation_xdb sys where database='$i';"|awk ' NR > 1 '|sed '$d')
              for T in `echo $Table_name`
               do
                   nz_groom ${i} $T -records >> $LOG
                   if [ $? -eq 0 ];then
                   echo "Completed: Groom of Table $T Database $i on `date +%y%m%d%H%M%S` " >>$LOG
                   else
                   echo "Failed: Groom of Table $T Database $i on  " >> $LOG
                   fi

               done
   done
echo " Find the Groom Report for Netezza `hostname` server in attachment"| mailx -s " Groom Report for Netezza $DAY `hostname` server on `date +%y%m%d%H%M%S` " -a $LOG "$DBA_email"
}
##############################
###checking the day
if [ $DAY == "Wed" ] || [ $DAY == "Sat" ]; then
        GROOM_DB_LIST=$DB_LIST_WED_SAT
echo "second block"
       groom_db_fn
        echo $DAY
elif [ $DAY == "Sun" ]; then
        echo $DAY
                GROOM_DB_LIST=$DB_LIST_SUN
                groom_db_fn
else
        echo "GROOM Dont not run on $DAY" > LOG
        exit;
fi

Script for NZHostbackup on IBM Netezza

##Script for NZHostbackup on IBM Netezza
## Manish Jaiswal
#!/bin/sh
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
DATE=`date +%Y-%m-%d:%H:%M:%S`
HOST=`hostname`
email_list=manish.jaiswal@gmail.com
EVENT_LOG_FILE_BEFORE=/export/home/nz/scripts/log/EVENT_LOG_FILE_BEFORE_$DATE.log
NZ_HOST_BACKUP_DMP_FILE=/dbbackup/nz_hostbackup/edw-ntz-001-lqc/nz_hostbackup_$DATE.dmp
NZ_HOST_BACKUP_LOG_FILE=/dbbackup/nz_hostbackup/edw-ntz-001-lqc/nz_hostbackup_$DATE.log
NPS_STATE=`nzstate | awk '{print $4}' | tr -d "[.']" | tr "[a-z]" "[A-Z]"`

# -----------------------------------------------------------------------------
# Make sure the system is online and no backups are running.
# -----------------------------------------------------------------------------
# ------------------------------------------------------------------------
# Make sure the system is online.
# ------------------------------------------------------------------------
if [ "${NPS_STATE}" = "ONLINE" ]
then
   echo "${NPS_STATE}"
SYSTEMSTATE=0

#elif [ "${NPS_STATE}" = "STOPPED" ]
#then
        echo "${NPS_STATE}"

else
   echo "NPS ${NPS_STATE} ONLINE REQUIRED EXITING!"
   echo  "NZHostbackup Required NPS state of online not the current state! Current state: [${NPS_STATE}]"|mailx -s "Notification:NZHOSTBACKUP  on  $HOST " $email_list
   exit;
fi

# ------------------------------------------------------------------------
# Make sure that there are no backups & Restore under execution.
# ------------------------------------------------------------------------
COUNT_OF_BACKUP_PROCESSES=`ps -ef | grep nzbackup | grep -v grep | wc -l`
COUNT_OF_RESTORE_PROCESSES=`ps -ef | grep nzrestore | grep -v grep | wc -l`

if [ ${COUNT_OF_BACKUP_PROCESSES} -eq 0 ] && [ ${COUNT_OF_RESTORE_PROCESSES} -eq 0 ]
then
        echo " NO Backup & Restore is running "
BACKUPSTATE=0
else
BR_COUNT=${COUNT_OF_BACKUP_PROCESSES} + ${COUNT_OF_RESTORE_PROCESSES}
     echo  "NPS having ${COUNT_OF_BACKUP_PROCESSES} RUNNING BACKUPS FOUND EXITING!"
     echo  "NZHostbackup  Catalog backups cannot run with other backups! Found ${BR_COUNT} running backup(s)."|mailx -s "Notification:NZHOSTBACKUP  on  $HOST" $email_list
     exit;
fi
# -----------------------------------------------------------------------------
# Disable the state change events on the system.
# -----------------------------------------------------------------------------
# ------------------------------------------------------------------------
# Log the state of the events on the system.
# ------------------------------------------------------------------------
nzevent show -maxColW 4096 -orient vertical   > ${EVENT_LOG_FILE_BEFORE}
RetCode=$?

if [ ${RetCode} -eq 0 ]
then
        echo "Successful"
else
        echo "FAILED!"
        echo "NZHostbackup Error logging system events! Error: [${RetCode}]"|mailx -s "Notification:NZHOSTBACKUP  on  $HOST " $email_list
        exit;
fi

# ------------------------------------------------------------------------
# Disable the events.
# ------------------------------------------------------------------------
# Cut the event listing down to the name of the event, the state, and the type.  Then loop on the output.
nzevent show -maxColW 4096 -orient vertical | grep -E  ^'Name|On |Event Type' | while read line
do

# If we're reading a Name then grab the 2nd field as the value.
if [ `echo ${line} | grep -c "^Name"` -eq 1 ]
then
        EvtName=`echo ${line} | awk '{print $2}'`
        continue
fi

# If we're reading a status line then grab the 2nd field as the value.
if [ `echo ${line} | grep -c "^On"` -eq 1 ]
then
        EvtOn=`echo ${line} | awk '{print $2}'`
        continue
fi

# If we're reading a type line then grab the 3rd field as the value.
if [ `echo ${line} | grep -c "^Event Type"` -eq 1 ]
then
        EvtType=`echo ${line} | awk '{print $3,$4,$5}'`
fi

# Only attempt to disable an event if we have all three values present.
if [ ${#EvtName} -gt 0 -a ${#EvtOn} -gt 0 -a ${#EvtType} -gt 0 ]
then
    # Only deal with the target event type.
    if [ "${EvtType}" = "Sys State Changed" ]
    then
        # If the event is enabled then we have something to do.
        # Otherwise we don't care.
        if [ "${EvtOn}" = "yes" ]
        then
           echo "   Disabling event: ${EvtName}"

           nzevent modify -name ${EvtName} -on false
           RetCode=$?

           if [ ${RetCode} -eq 0 ]
           then
               echo "Successful"
           else
               echo "FAILED!"
               echo "NZHOSTBACKUP DISABLE event error: ${EvtName} on ${BACKUP_HOST}! [${RetCode}]"|mailx -s "Notification:NZHOSTBACKUP  on  $HOST " $email_list
               exit;
           fi
        fi
    fi
fi
done

# ------------------------------------------------------------------------
# Execute the catalog backup.
# ------------------------------------------------------------------------
echo "Performing host catalog backup of ${HOST}"

BACKUP_START=`date "+%Y-%m-%d %H:%M:%S"`

nzhostbackup ${NZ_HOST_BACKUP_DMP_FILE}       > ${NZ_HOST_BACKUP_LOG_FILE} 2>&1
RetCode=$?

# Check the outcome.
if [ ${RetCode} -eq 0 ]
then
     BACKUP_END=`date "+%Y-%m-%d %H:%M:%S"`
     BACKUP_STATUS="COMPLETED"
echo "NZHOSTBACKUP host catalog backup of ${HOST} Success [${RetCode}]"|mailx -s "Success :NZHOSTBACKUP  on  $HOST " $email_list
else
     BACKUP_STATUS="FAILED"
     rm -f ${NZ_HOST_BACKUP_DMP_FILE}
     echo "NZHOSTBACKUP host catalog backup of ${HOST} failure! [${RetCode}]"|mailx -s "Failed:NZHOSTBACKUP  on  $HOST " $email_list

fi
# ------------------------------------------------------------------------
# Enable the events.
# ------------------------------------------------------------------------
# Cut the event listing down to the name of the event, the state, and the type.  Then loop on the output.
nzevent show -maxColW 4096 -orient vertical | grep -E  ^'Name|On |Event Type' | while read line
do

  # If we're reading a Name then grab the 2nd field as the value.
  if [ `echo ${line} | grep -c "^Name"` -eq 1 ]
  then
          EvtName=`echo ${line} | awk '{print $2}'`
          continue
  fi

  # If we're reading a status line then grab the 2nd field as the value.
  if [ `echo ${line} | grep -c "^On"` -eq 1 ]
  then
          EvtOn=`echo ${line} | awk '{print $2}'`
          continue
  fi

  # If we're reading a type line then grab the 3rd field as the value.
  if [ `echo ${line} | grep -c "^Event Type"` -eq 1 ]
  then
          EvtType=`echo ${line} | awk '{print $3,$4,$5}'`
  fi

  # Only attempt to Enable an event if we have all three values present.
  if [ ${#EvtName} -gt 0 -a ${#EvtOn} -gt 0 -a ${#EvtType} -gt 0 ]
  then
      # Only deal with the target event type.
      if [ "${EvtType}" = "Sys State Changed" ]
      then
          # If the event is disabled then we have something to do.
          # Otherwise we don't care.
          if [ "${EvtOn}" = "no" ]
          then
              echo" Enabling event: ${EvtName}"
              nzevent modify -name ${EvtName} -on true
              RetCode=$?

              if [ ${RetCode} -eq 0 ]
              then
                      echo "Successful"
              else
              echo "FAILED!"
              echo "NZHOSTBACKUP ENABLE event error: ${EvtName} on ${BACKUP_HOST}! [${RetCode}]"|mailx -s "Notification:NZHOSTBACKUP  on  $HOST " $email_list      
 exit;
              fi
          fi
      fi
  fi
done
###Done