R12.2 Apps DBA. Powered by Blogger.

RMAN list status of database backups.

No comments :
[orAPPROD@ordb01 rman]$ cat /home/oracle/scripts/APPROD/backup_rman_list_backups.sh
#!/bin/sh
#
#  File       : backup_rman_list_backups.sh
#
#  Description: RMAN list status of database backups.
export SCRIPT_VERSION=1.4
#
# #################
# APPROD
. /APPROD/oracle/product/1020/APPROD_ordb01.env
export ORACLE_SID=APPROD
export ORACLE_HOME=/APPROD/oracle/product/1020
# #################
export BASE_DIR=/home/oracle/scripts
export SCRIPTSLOG=/backup/database/APPROD/backupsets/logfiles

export PATH=$ORACLE_HOME/bin:$PATH
export DAY=`date -u +%a`
export DATE=`date "+%m%d"`
export MONTH=`date -u +%B`
export SERVER_NAME=`hostname|cut -f1 -d.`
export BASE_DIR=/home/oracle/scripts
export SCRIPTS=$BASE_DIR/$ORACLE_SID
export SCRIPT_PREFIX=`basename $0|cut -d"." -f1`
export SCRIPT=$SCRIPT_PREFIX.sh
export LOG_FILE=$SCRIPTSLOG/logs/$SCRIPT_PREFIX.log

export TEMP_FILE=/tmp/$SCRIPT_PREFIX.util
export TEMP_FILE2=/tmp/$SCRIPT_PREFIX.util2
export ERROR_LOG=$SCRIPTSLOG/logs_history/$SCRIPT_PREFIX\_$MONTH.errors
export HISTORY_LOG=$SCRIPTSLOG/logs_history/$SCRIPT_PREFIX\_$MONTH.log
export MAIL_FILE_GOOD=$SCRIPTS/alerts_good/$SCRIPT_PREFIX.alert
export MAIL_FILE_BAD=$SCRIPTS/alerts_bad/$SCRIPT_PREFIX.alert

#
# Mail procedures
#
mail_good_level1 ()
{
cat ${BASE_DIR}/common/dba_error_messages.txt |grep DBA-9999|mail -s ":) $ORACLE_SID: Backup Listing Successful" `cat ${BASE_DIR}/common/mailing_list_level2.txt`  < ${MAIL_FILE_GOOD}
}
mail_bad_level1 ()
{
cat ${BASE_DIR}/common/dba_error_messages.txt |grep DBA-0006|mail -s ":( $ORACLE_SID: Backup Listing  Failed" `cat ${BASE_DIR}/common/mailing_list_level2.txt`  < ${MAIL_FILE_BAD}
}

#
# Backup procedure
#
LISTBACKUPS()
{
$ORACLE_HOME/bin/rman target APDBACKUP/` cat ${BASE_DIR}/common/dba_names.txt| grep ^$ORACLE_SID|grep APDBACKUP|cut -f3`@${ORACLE_SID} nocatalog <<!
list backup;
exit
!
}
LISTARCHIVES()
{
$ORACLE_HOME/bin/sqlplus -s APDBACKUP/` cat ${BASE_DIR}/common/dba_names.txt| grep ^$ORACLE_SID|grep APDBACKUP|cut -f3`@${ORACLE_SID}<<!
set pagesize 4000 linesize 400 trimspool on trimout on heading off
set termout off
col today new_value today
select to_char(sysdate,'yyyy/mm/dd') today from sys.dual;
set termout on heading on

prompt
prompt ${ORACLE_SID} - Archive Log History - &today
prompt

col time                     format a20              heading 'Date/Time'
col sequence#           format 9999999999       heading 'Sequence#'
col first_change#      format 9999999999999    heading 'Low|Change#'
col next_change#      format 9999999999999    heading 'High|Change#'
col name                    format a60              heading 'Archive'
col ARCHIVED        format a9               heading 'Archived?'
col DELETED           format a8               heading 'RMAN|Deleted?'
col STATUs                format a12              heading 'Status'

select
   to_char(first_time,'yyyy/mm/dd:hh24:mi:ss') first_time
  ,sequence#
  ,name
  ,ARCHIVED
  ,DELETED
  ,decode(STATUS,'D','Deleted','A','Available','U','Unavailable','X','Expired','Unknown') STATUS
  ,BACKUP_COUNT
  ,first_change#
  ,next_change#
from
  v\$archived_log
order by first_time
-- where first_time > sysdate - 7
/

prompt
prompt +++ End of Report +++
prompt
exit
!
}
#
# Run listings
#
echo "Start: `date '+%Y/%m/%d at %H:%M'`"                             > ${LOG_FILE}
echo "SID:${ORACLE_SID} Script:${SCRIPT} Version:${SCRIPT_VERSION}"  >> ${LOG_FILE}
#
LISTBACKUPS    > ${TEMP_FILE}
LISTARCHIVES  >> ${TEMP_FILE}
#
# Check if listing was successful
#
check_stat=`cat ${TEMP_FILE}|grep -E "ORA-|RMAN-" |wc -l`;oracle_num=`expr $check_stat`
if [ $oracle_num -gt 0 ]
#
# If error found
#
  then
  echo `cat ${BASE_DIR}/common/dba_error_messages.txt |grep DBA-0006`  >> ${LOG_FILE}
  echo "Messages follow..."                                            >> ${LOG_FILE}
  cat ${TEMP_FILE}                                                     >> ${LOG_FILE}
  echo " "                                                             >> ${LOG_FILE}
  echo "End: `date '+%Y/%m/%d at %H:%M'`"                              >> ${LOG_FILE}
  cat ${LOG_FILE}                                                      >> ${HISTORY_LOG}
  cat ${LOG_FILE}                                                       > ${MAIL_FILE_BAD}
  mail_bad_level1
#
else
#
# No problem
#
  echo `cat ${BASE_DIR}/common/dba_error_messages.txt |grep DBA-9999` >> ${LOG_FILE}
  echo " "                                                            >> ${LOG_FILE}
  echo "End: `date '+%Y/%m/%d at %H:%M'`"                             >> ${LOG_FILE}
  cat ${LOG_FILE}                                                      > ${MAIL_FILE_GOOD}
  cat ${TEMP_FILE}                                                    >> ${LOG_FILE}
  cat ${LOG_FILE}                                                     >> ${HISTORY_LOG}
#  mail_good_level1
fi

exit
[orAPPROD@ordb01 rman]$
[orsuprod@ordb01 common]$ cat mailing_list_level2.txt
apdbablogspot.com

No comments :

Post a Comment

Note: only a member of this blog may post a comment.