diff --git a/instance-applications/120-ibm-db2u-database/files/Run_Backup.sh b/instance-applications/120-ibm-db2u-database/files/Run_Backup.sh index 72f29f0c8..7e865bb4d 100755 --- a/instance-applications/120-ibm-db2u-database/files/Run_Backup.sh +++ b/instance-applications/120-ibm-db2u-database/files/Run_Backup.sh @@ -1,8 +1,6 @@ #!/bin/bash -#set -x - ######################################################### -# Run_Backup.sh +# Run_Backup.sh # Run_Backup.sh will be called from the Cron Jobs # This script will list all local databases running in the instance on a node. It will call the # DB2_Backup.sh script to run a backup for each running database. @@ -17,93 +15,137 @@ # NUMOFBKUPTOKEEP = This defines the number of days to keep a backup image on local disk # # Variables determined by the environment -# BACKUPTYPE = Is determined from the `date` command and the DAYOFFULL value +# BKPTYPE = Is determined from the `date` command and the DAYOFFULL value # DB2INSTANCE = Pulled from the environment # HOSTNAME # DBNAME = Pulled from the `db2 list db directory` # # Backup command issued -# ./DB2_Backup.sh ${DB2INSTANCE} ${DBNAME} ${NUMOFBKUPTOKEEP} ${BACKUPTYPE} 2>>.BackupLOG.stderr > .BackupLOG.out +# ./DB2_Backup.sh ${DB2INSTANCE} ${DBNAME} ${NUMOFBKUPTOKEEP} ${BKPTYPE} 2>>.BackupLOG.stderr > .BackupLOG.out +# +# -- Revision of script to include new ICD URL ######################################################### +# -- Source the Props File . /mnt/backup/bin/.PROPS +# -- Standard Parameters DBINSTANCE=`whoami` HOSTNAME=`hostname` -BACKUP_DIR=${HOME}/bin -BACKUP_SCRIPT=DB2_Backup.sh DATETIME=`date +%Y-%m-%d_%H%M%S`; +DOW=`date | awk '{print $1}'` + +# -- Verify and source db2profile -if [ ! -f "${HOME}/sqllib/db2profile" ] -then +if [[ ! -f "${HOME}/sqllib/db2profile" ]]; then echo "ERROR - ${HOME}/sqllib/db2profile not found" EXIT_STATUS=1 else . ${HOME}/sqllib/db2profile fi +# -- Debug Mode +set -x + +# -- Backup Parameters +INSTANCE_HOME=`/usr/local/bin/db2greg -dump | grep -ae "I," | grep -v "/das," | grep "${DBINSTANCE}" | awk -F ',' '{print $5}'| cut -d/ -f 1,2,3,4,5` +SCRIPT_DIR=${INSTANCE_HOME}/bin +BACKUP_SCRIPT="${SCRIPT_DIR}/DB2_Backup.sh" +CUSTNAME=`hostname | sed 's/c-db2wh-//; s/c-//; s/-db2u-0//; s/db2u/-/; s/-manage//;' | tr '[:lower:]' '[:upper:]'` +BUCKET_ALIAS=`db2 list storage access | grep ${CONTAINER} -B4 | grep ALIAS | awk -F '=' '{print $2}'` +HSTYPE="Backup" +ICD_LOG=${SCRIPT_DIR}/.Maillive.log + +# -- Valid only for MAS-CP4D customers +if (( ${CUSTNAME} )) ; then + CUSTNAME=`echo ${CONTAINER} | awk -F '-backup-' '{print $2}' | awk -F '-pr-' '{print $1}' | tr '[:lower:]' '[:upper:]'` +fi + +# -- Database Environment +if [[ ${BUCKET_ALIAS} == "IBMCOS" ]]; then + DBENV="MAS MS" +else + DBENV="MAS SaaS" +fi + +# -- Create ICD Incident , If Backup fails + +CREATE_ICD() { + HTYPE=`echo ${HSTYPE} | tr '[:lower:]' '[:upper:]'` + DES="$1" + echo "############################" >> ${ICD_LOG} + LONGDES=`cat ${ICD_LOG} | sed 's/"//g' | sed "s/'//g"` + LONGDES=`echo "
${LONGDES} "`
+
+ # -- Verify the ICD URL Status
+ if curl -k -s --connect-timeout 3 ${ICD_URL_SAAS} >/dev/null; then
+ CURL_REQ="--request POST --url ${ICD_URL_SAAS} "
+ AUTH_REQ="apikey: ${ICD_API_KEY}"
+ fi
-DOW=`date | awk '{print $1}'`
- if [ ${DOW} = ${DAYOFFULL} ] ; then
- BACKUPTYPE=full
- else
- BACKUPTYPE=inc
- fi
+ # -- Generate Curl Syntax to push to ICD
+ cat << ! >.curl_${DBNAME}_ICD.sh
+ curl ${CURL_REQ} \
+ --header '${AUTH_REQ}' \
+ --header 'Content-Type: application/json' \
+ --data '{
+ "description":"${DES}",
+ "reportedpriority":4,
+ "internalpriority":4,
+ "reportedby":"DB2",
+ "affectedperson":"${DBENV}",
+ "ownergroup":"HSDBA",
+ "description_longdescription":"${LONGDES}",
+ "siteid":"001",
+ "classstructureid":"1341",
+ "classificationid":"IN-DBPERF",
+ "hshost":"${HOSTNAME}",
+ "hstype":"${HTYPE}"
+ }'
+!
+ /bin/bash .curl_${DBNAME}_ICD.sh > .curl_${DBNAME}_ICD.out 2>&1
+
+}
+
+# -- Verify the day of the week
+if [[ ${DOW} = ${DAYOFFULL} ]] ; then
+ BKPTYPE="FULL"
+else
+ BKPTYPE="DIFF"
+fi
+
+# -- Loop through the available databases in the instance
DBS=`db2 list db directory | grep -B5 "Indirect" | grep "Database name" | awk '{ print $4 }'`
for DBNAME in ${DBS}
do
- cd ${BACKUP_DIR}
- ./DB2_Backup.sh ${DB2INSTANCE} ${DBNAME} ${NUMOFBKUPTOKEEP} ${BACKUPTYPE} 2>.BackupLOG.stderr > .BackupLOG.out
-
- RC=$?
- if [ ${RC} -ne 0 ]; then
-
- longdes="Failure to start the Backup job ${DATETIME} CUST=${CUSTNAME} ${RC}"
- ## Send Failure notification to a slack channel ##
- cat << ! >.curl_${DBNAME}_RUN.sh
- if [[ -n "${SLACKURL}" ]]; then
- curl -X POST -H 'Content-type: application/json' --data '{"text":"$longdes"}' $SLACKURL
- fi
+ cd ${SCRIPT_DIR}
+ ${BACKUP_SCRIPT} ${DB2INSTANCE} ${DBNAME} ${NUMOFBKUPTOKEEP} ${BKPTYPE} 2>.BackupLOG.stderr > .BackupLOG.out
+ RC=$?
+ if [[ ${RC} -ne 0 ]]; then
+ LONGDES="Failure to start the Backup job ${DATETIME} CUST=${CUSTNAME} ${RC}"
+ # -- Send Failure notification to a slack channel
+ cat << ! >.curl_${DBNAME}_RUN.sh
+ curl -X POST -H 'Content-type: application/json' --data '{"text":"$LONGDES"}' ${SLACKURL}
!
-/bin/bash .curl_${DBNAME}_RUN.sh > .curl_${DBNAME}_RUN.out 2>&1
-
- ##### Create ICD Incident ####
- ####### If Backup fails ###
- des="${DBINSTANCE} - Backup - ${HOSTNAME} ${DBNAME} ${CUSTNAME} - MASMS -- Backup Failed"
- echo "TESTING $instance - Backup - $ ${DBNAME} - Backup Failed" > .Maillive.log
- echo "############################" >> .Maillive.log
- #cat $BACK_LOG >> .Maillive.log
- longdes=`cat .Maillive.log | sed 's/"//g' | sed "s/'//g"`
- ICD_URL="https://servicedesk.mro.com"
- if ! curl -k -s --connect-timeout 3 ${ICD_URL} >/dev/null; then
- ICD_URL="https://servicedesk.cds.mro.com"
- fi
+ /bin/bash .curl_${DBNAME}_RUN.sh > .curl_${DBNAME}_RUN.out 2>&1
-cat << ! >.curl_${DBNAME}_ICD.sh
- curl --insecure --location --request POST "${ICD_URL}/maximo_mif/oslc/os/hsincident?lean=1" \
- --header "Authorization: Basic ${ICD_AUTH_KEY}" \
- --header 'Content-Type: application/json' \
- --data '{
- "description":"$des",
- "reportedpriority":4,
- "internalpriority":4,
- "reportedby":"DB2",
- "affectedperson":"CTGINST1",
- "description_longdescription":"$longdes",
- "siteid":"001",
- "classstructureid":"1341",
- "classificationid":"IN-DBPERF",
- "hshost":"{servicedesk-pdb-sjc03-2.cds.mro.com:0:50}",
- "hstype":"BACKUP"
- }'
-!
-if [[ -n "${ICD_AUTH_KEY}" ]]; then
- /bin/bash .curl_${DBNAME}_ICD.sh > .curl_${DBNAME}_ICD.out 2>&1
-fi
+ # -- Create ICD ticket if fails
+ DES="${CUSTNAME} - ${DBENV} - ${DBNAME} - ${HOSTNAME} -- Failed to Start Backup!! "
+ CREATE_ICD "${DES}"
+ fi
+
+ # -- Execute Online Reorgs for qualified tables and indexes after every Full Backup
+ if [[ ${DOW} = ${DAYOFFULL} ]] ; then
+ /bin/bash ${SCRIPT_DIR}/reorgTablesIndexesInplace.sh -db ${DBNAME} -s MAXIMO -tb_stats -ix_stats -window 240 -tr > ${HOME}/maintenance/logs/reorgTablesIndexesInplace_${DATETIME}.log 2>&1
+ fi
-fi
done
-/bin/bash ${HOME}/bin/runstats_rebind.sh >${HOME}/bin/.runstats_rebind.out 2>&1
-/bin/bash ${HOME}/bin/grant_check.sh bludb >${HOME}/bin/.grant_check.out 2>&1
+
+
+# -- Exeucte Runstats and Rebind for all tables daily
+/bin/bash ${SCRIPT_DIR}/runstats_rebind.sh >${SCRIPT_DIR}/.runstats_rebind.out 2>&1
+#/bin/bash ${SCRIPT_DIR}/grant_check.sh bludb >${SCRIPT_DIR}/.grant_check.out 2>&1
+
+# -- END OF SCRIPT