oper@bildbtast1:/opt/tivoli/tsm/SCRIPTS/SCHEDULE/db_day/CUST01 >more sched_db_day.ksh #!/bin/ksh # -- Tivoli Schedule Script # ------------------------------------------------ # -- Script Name : sched_db_day.ksh # -- Schedule Name : # -- Schedule Start : # # ------------------------------------------------ # -- Load Configure Environment export DSM_DIR=/opt/tivoli/tsm/client/oracle/CUST01 export DSM_CONFIG=${DSM_DIR}/dsm.opt export DSM_LOG=${DSM_DIR} # Start Schedule Process dsmc schedule & # ----------------------------------------------- oper@bildbtast1:/opt/tivoli/tsm/SCRIPTS/SCHEDULE/db_day/CUST01 >more db_day_rman.ksh #!/bin/ksh umask 022 SCRIPT_NAME=db_day ORACLE_SID=CUST01 ORACLE_HOME=/CUS/appl/oracle/product/8.1.7 NLS_LANG=AMERICAN_AMERICA.TH8TISASCII LOGRETENTION=14 SCRIPT_DIR=/opt/tivoli/tsm/SCRIPTS/SCHEDULE/${SCRIPT_NAME}/${ORACLE_SID} LOG_DIR=${SCRIPT_DIR}/Log SCRIPT_ARC=/tmp/${SCRIPT_NAME}_arc.rman bakLOG=${LOG_DIR}/${SCRIPT_NAME}LOG.log.`date +%Y%m%d%H%M` DATE=$(date +"%d%m%y") STIME=$(date "+%d/%m/%Y %H:%M:%S") TODAY=`date +%d` DAYOFWEEK=`date +%a` if [ "$1" == "-level0" ]; then SCRIPT_RMAN=/opt/tivoli/tsm/SCRIPTS/SCHEDULE/${SCRIPT_NAME}/${ORACLE_SID}/${SCRIPT_NAME}_inc0.rman elif [ "$1" == "-level2" ]; then SCRIPT_RMAN=/opt/tivoli/tsm/SCRIPTS/SCHEDULE/${SCRIPT_NAME}/${ORACLE_SID}/${SCRIPT_NAME}_inc2.rman elif [ $TODAY -ge 2 -a $TODAY -le 8 -a $DAYOFWEEK == "Sun" ]; then SCRIPT_RMAN=/opt/tivoli/tsm/SCRIPTS/SCHEDULE/${SCRIPT_NAME}/${ORACLE_SID}/${SCRIPT_NAME}_inc0.rman else SCRIPT_RMAN=/opt/tivoli/tsm/SCRIPTS/SCHEDULE/${SCRIPT_NAME}/${ORACLE_SID}/${SCRIPT_NAME}_inc2.rman fi ######################################################################################## _REMOVE_EXPLOG() { find ${LOG_DIR}/${SCRIPT_NAME}LOG* -mtime +${LOGRETENTION} -exec rm {} \; return $? } ############################################################################################################ _BAKDB() { su - oracle -c " export ORACLE_SID=${ORACLE_SID} export ORACLE_HOME=${ORACLE_HOME} export NLS_LANG=${NLS_LANG} export NLS_DATE_FORMAT=\"DD/MM/YYYY HH24:MI:SS\" PATH=\$ORACLE_HOME/bin:\$PATH export PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:\$HOME/bin:/usr/bin/X11:/sbin:.:/usr/lbin:\$PATH rman target / cmdfile=${SCRIPT_RMAN} exit \$? " return $? } ############################################################################################################ _BAKARC() { echo "connect catalog cust01/cust01@rcnbs01;" > ${SCRIPT_ARC} echo "run {" >> ${SCRIPT_ARC} echo "allocate channel t1 type 'sbt_tape' parms 'ENV=(BLKSIZE=1048576, TDPO_OPTFILE=/opt/tivoli/tsm/client/oracle/CUST01/tdpo.opt)'; " >> ${SCRIPT_ARC} echo "sql 'alter system archive log current';" >> ${SCRIPT_ARC} echo "backup" >> ${SCRIPT_ARC} echo " format 'Daily_backup_Archive_%d_%s_%p'" >> ${SCRIPT_ARC} echo " (archivelog from time '${STIME}');" >> ${SCRIPT_ARC} echo "release channel t1;" >> ${SCRIPT_ARC} echo "}" >> ${SCRIPT_ARC} su - oracle -c " export ORACLE_SID=${ORACLE_SID} export ORACLE_HOME=${ORACLE_HOME} export NLS_LANG=${NLS_LANG} export NLS_DATE_FORMAT=\"DD/MM/YYYY HH24:MI:SS\" PATH=\$ORACLE_HOME/bin:\$PATH export PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:\$HOME/bin:/usr/bin/X11:/sbin:.:/usr/lbin:\$PATH rman target / cmdfile=${SCRIPT_ARC} exit \$? " return $? } ############################################################################################################ _SEND_MAIL() { P1="pornchai_pip@telecomasia.co.th" P2="Sarawut_You@telecomasia.co.th" P3="OperDC2@telecomasia.co.th" SUBJECT="Daily CUST01 Backup On BILDBTAST1" cat ${bakLOG} |mailx -s "${SUBJECT}" ${P1} ${P2} ${P3} } ############################################################################################################ _MAIN() { echo "Start backup of $ORACLE_SID at " `date '+%d/%m/%Y %H:%M:%S'` _REMOVE_EXPLOG _BAKDB RC=$? if [ $RC -ne 0 ] then echo "Backup database is Incompleted with return code $RC " echo "Finish backup of $ORACLE_SID at " `date '+%d/%m/%Y %H:%M:%S'` return $RC fi echo "Backup database is Completed with reture code $RC " echo "*****************************************************************************************" _BAKARC RC=$? if [ $RC -ne 0 ] then echo "Backup archived log file is Incompleted with return code $RC " else echo "Backup archived log file is Completed with reture code $RC " fi echo "Finish backup of $ORACLE_SID at " `date '+%d/%m/%Y %H:%M:%S'` echo "*****************************************************************************************" return $RC } ############################################################################################################ _MAIN > ${bakLOG} 2>&1 _SEND_MAIL