Home » RDBMS Server » Server Utilities » How to get a UNIX return code from RMAN in Solaris (Oracle 10G, version 2, UNIX)
How to get a UNIX return code from RMAN in Solaris [message #350886] Fri, 26 September 2008 17:42 Go to next message
stevekerver
Messages: 19
Registered: January 2008
Junior Member
Hi- I'm trying to figure out how to get an e-mail sent to me whenever the RMAN backup job that runs under UNIX crontab fails.
I've got the e-mailing part down, what I'm missing though is the part about the exit codes.
Basically, what I want is to examine the exit code after RMAN completes, and if the exit code isn't 0, I want it to send an e-mail indicating the failure.

We are using Solaris 10, BTW.

The script I'm using is below:

#!/bin/ksh

#If the script fails, the LINE_NUMBER will indicate WHERE in the script the failure happened, and the check_errs() function will check for the exit code, and e-mail the DBA a failure alert.
export LINE_NUMBER=0

check_errs()
{
    if [ "${1}" -ne "0" ]; then
     echo "CURRENT DATABASE BACKUP JOB FOR "`date`" HAS FAILED at line number "$LINE_NUMBER". Please check the logs in /home/oracle/DATABASE_BACKUP_SCRIPT/backup_logs for more information." | /opt/local/sbin/sendmail -f $ORACLE_SID address me@myaddress.com
    exit ${1}
  fi
}

cd
. ./.profile

export LINE_NUMBER=1
check_errs $?

$ORACLE_HOME/bin/rman target / << EOF
RUN {
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 2 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO 'DISK';
CONFIGURE CONTROLFILE AUTOBACKUP OFF;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE TO '%F'; 
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; 
CONFIGURE DEVICE TYPE SBT_TAPE PARALLELISM 2 BACKUP TYPE TO BACKUPSET; 
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET; 
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; 
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; 
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE SBT_TAPE TO 1; 
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; 
CONFIGURE MAXSETSIZE TO UNLIMITED; 
CONFIGURE ENCRYPTION FOR DATABASE OFF; 
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; 
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; 
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/home/oracle/DATABASE_BACKUP_SCRIPT/snapcf_SBARPRD1.f';
backup database;
}
EXIT $status;
EOF

export LINE_NUMBER=2
check_errs $?

/u01/app/oracle/product/10.2.0/db_1/bin/rman target / << EOF
RUN {
allocate channel CHAN_1 device type disk;
crosscheck backup;
crosscheck archivelog all;
crosscheck copy;
delete noprompt obsolete;
delete noprompt expired backup;
delete noprompt expired archivelog all;
}
EXIT $status;
EOF

export LINE_NUMBER=3
check_errs $?

#Now, recycle the listener logs so that there are only 7 days worth of listener log history.
cd $ORACLE_HOME/network/log
export THE_DATE=$(date +"%m_%d_%Y")
$ORACLE_HOME/bin/lsnrctl set log_status off
mv listener.log listener$THE_DATE.log
$ORACLE_HOME/bin/lsnrctl set log_status on

export LINE_NUMBER=4
check_errs $?

#Now, trim the alert log so that there is only 10 days worth of alert log history.
cd /u01/app/oracle/admin/SBARDEV1/bdump
mv alert_$ORACLE_SID.log alert_$ORACLE_SID$THE_DATE.log
touch alert_$ORACLE_SID.log
chmod 0640 alert_$ORACLE_SID.log

export LINE_NUMBER=5
check_errs $?

# Now, find any trace, backup, alert, and listener log files older than 10 or 7 days and delete them.
find /u01/app/oracle/admin/$ORACLE_SID -mtime +10 -exec rm {} \;
export LINE_NUMBER=6
check_errs $?
find /home/oracle/DATABASE_BACKUP_SCRIPT/backup_logs -mtime +7 -exec rm {} \;
export LINE_NUMBER=7
check_errs $?
find $ORACLE_HOME/network/log/listener* -mtime +7 -exec rm {} \;
export LINE_NUMBER=8
check_errs $?
find /u01/app/oracle/admin/SBARDEV1/bdump* -mtime +10 -exec rm {} \;
export LINE_NUMBER=9
check_errs $?




See- if you run this script, and RMAN experiences a failure, it doesn't trap the exit code. Confused




Re: How to get a UNIX return code from RMAN in Solaris [message #350899 is a reply to message #350886] Sat, 27 September 2008 01:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68728
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Use "log" to get the log in a file and scan it for any error with "grep", "awk" or any other tool you like.

Regards
Michel
Re: How to get a UNIX return code from RMAN in Solaris [message #350925 is a reply to message #350886] Sat, 27 September 2008 12:45 Go to previous message
ebrian
Messages: 2794
Registered: April 2006
Senior Member
You should use $? instead of $status to obtain the exit code.

Plus your in your current configuration, the exit status will always be 0 since it simply follows an export command.
Previous Topic: How to take logical incremental backup
Next Topic: Problem with EXPDP
Goto Forum:
  


Current Time: Tue Dec 24 10:18:07 CST 2024