UNIX script to check archivelog backup [message #394123] |
Wed, 25 March 2009 14:57 |
anjum.suri
Messages: 14 Registered: February 2008
|
Junior Member |
|
|
Hi All
I am very new to programming/scripting so need some help from UNIX gurus; I need to write a script that check if the archivelog backup went successful or failed; I have written below script that goes to the directory where rman log files for archivelog backups resides and grab "Exit Status" from the archivelog from those files...now I am stuck with the IF part of the script (which I have commented) as in I want to print backup either succeded or failed based on the exit status...
I have multiple databases running on one machine; at the end I want a report to be emailed to me with details of which databases archivelog backups failed and for which they went successful
Could anyone please advice?
Script
------
chkbck ()
{
for i in `ls /ora/rman/logs/`;
do
ls -latr /ora/rman/logs/$i/b* | tail -1 | nawk '{ print $9 }';
done
}
for i in `chkbck`;
do
print $i
grep Exit $i
done > $TMP_FILE
#if egrep -i 'exit status [^0]' $TMP_FILE
#print "Backup Failed"
#fi
OUTPUT
--------
/ora/rman/scripts> cat chkbackup.tmp
/ora/rman/logs/DBADB1D/backup_DBADB1D_24Mar09-20:29:28.log
Exit Status 0
/ora/rman/logs/DBADB1P/backup_DBADB1P_24Mar09-19:41:48.log
Exit Status 0
/ora/rman/logs/DBADB2D/backup_DBADB2D_24Mar09-20:16:40.log
Exit Status 0
/ora/rman/logs/DBADB4D/backup_DBADB4D_05Jan09-16:09:39.log
Exit Status 0
/ora/rman/logs/DBADB7D/backup_DBADB7D_24Mar09-19:41:33.log
Exit Status 1
/ora/rman/logs/NO_SID/backup_arch_NO_SID_05Jan09-15:49:15.log
Exit Status 127
/ora/rman/logs/ORADB1P/backup_arch_ORADB1P_04Sep07-07:42:22.log
Exit Status 0
/ora/rman/logs/PAULTST/backup_PAULTST_19Jan09-23:53:03.log
Exit Status 1
/ora/rman/logs/PJ10G1D/backup_PJ10G1D_24Mar09-19:41:14.log
Exit Status 1
/ora/rman/logs/REMDY1X/backup_REMDY1X_04Dec08-22:04:41.log
Exit Status 1
|
|
|
|
|
|
|
Re: UNIX script to check archivelog backup [message #394367 is a reply to message #394123] |
Thu, 26 March 2009 12:25 |
anjum.suri
Messages: 14 Registered: February 2008
|
Junior Member |
|
|
Thanks Mahesh
Find attached log file from the RMAN backup; I need to pull database name (as in the log file DBADBID) from this file and the last line that tells exit status (if 0 then successful else failed)..The database name is also there in the file name DBADB1D & DBADB1P
I have written below script which is working fine but instead of filename I need database name..Any help will be much appreciated
TMP_FILE='/ora/rman/scripts/tmp_chk.log'
chkbck ()
{
for i in `ls /ora/rman/logs/`;
do
find /ora/rman/logs/$i/backup_a*.log -mtime -1 2>/dev/null
done
}
for i in `chkbck`;
do
print $i
# grep Exit $i
if egrep -i 'exit status [^0]' $i
then
print "Backup Failed"
else
print "Backup Successful"
fi
done > $TMP_FILE
OUTPUT
------
/ora/rman/logs/DBADB1D/backup_arch_DBADB1D_26Mar09-15:03:43.log
Backup Successful
/ora/rman/logs/DBADB1P/backup_arch_DBADB1P_26Mar09-12:15:15.log
Exit Status 1
Backup Failed
[Updated on: Thu, 26 March 2009 13:11] by Moderator Report message to a moderator
|
|
|
Re: UNIX script to check archivelog backup [message #394403 is a reply to message #394367] |
Thu, 26 March 2009 17:01 |
|
Mahesh Rajendran
Messages: 10708 Registered: March 2002 Location: oracleDocoVille
|
Senior Member Account Moderator |
|
|
In future, please use CODE tags to format the code.
Here is a simple working example.
You can make it any fancier you want.
It still has room to improvement to fit your need. I will leave that for you.
Created some logfiles, just to imitate your naming convention.
Kaapi:shell magvivek$ ls -lart
total 56
drwxr-xr-x 9 magvivek staff 306 Mar 26 16:32 ..
-rw-r--r-- 1 magvivek staff 14 Mar 26 16:34 backup_arch_DBADB1D_26Mar09-15:03:43.log
-rw-r--r-- 1 magvivek staff 14 Mar 26 16:35 backup_arch_DBADB23D_26Mar09-15:03:43.log
-rw-r--r-- 1 magvivek staff 14 Mar 26 16:36 backup_arch_DBADB4D_26Mar09-15:03:43.log
-rw-r--r-- 1 magvivek staff 14 Mar 26 16:37 backup_arch_DBADBD_26Mar09-15:03:43.log
-rw-r--r-- 1 magvivek staff 14 Mar 26 16:37 backup_arch_DBADB2D_26Mar09-15:03:43.log
-rwxr-xr-x 1 magvivek staff 583 Mar 26 17:51 somescript
-rw-r--r-- 1 magvivek staff 110 Mar 26 17:51 thislog
drwxr-xr-x 9 magvivek staff 306 Mar 26 17:51 .
This simple script will read each file,
take the last line and dbname (from the filename itself).
Comments inline.
Kaapi:shell magvivek$ cat somescript
#reset the log file
rm thislog
#look for a particular pattern match. I guess from logfiles you provided
# the database Names start with DBA
ls -lart *DBA* | awk '{print $9}' | while read fname
do
#based on the sample you have give, seems
#the dbname is third field, separated by underscore.
dbname=`echo $fname|cut -d"_" -f3`
#status is in last line
dbstatus=`tail -1 $fname`
#Just for Debugging
echo $dbname,$dbstatus
#redirect the output to another file
echo $dbname,$dbstatus >>thislog
done
#mail it yourself, do whatever you want here.
#file will be deleted when called next time.
A sample run
Kaapi:shell magvivek$ ./somescript
DBADB1D,Exit Status 1
DBADB23D,Exit Status 0
DBADB4D,Exit Status 0
DBADBD,Exit Status 1
DBADB2D,Exit Status 1
Kaapi:shell magvivek$ cat thislog
DBADB1D,Exit Status 1
DBADB23D,Exit Status 0
DBADB4D,Exit Status 0
DBADBD,Exit Status 1
DBADB2D,Exit Status 1
You can make it any fancier you want.
You can replace "Exit Status" to success/failure.
Add some html tags, create a tabular output .
missed the files like
>>/ora/rman/logs/ORADB1P/backup_arch_ORADB1P_04Sep07-07:42:22.log
Just
instead of
>>ls -lart *DBA*
use
and
>>/ora/rman/logs/PAULTST/backup_PAULTST_19Jan09-23:53:03.log
instead of 3 field separated by '_' use, second field to identify the dbname.
If your files are of mixed pattern, you may want to tweak the pattern matching.
[Updated on: Thu, 26 March 2009 18:43] Report message to a moderator
|
|
|
Re: UNIX script to check archivelog backup [message #399698 is a reply to message #394123] |
Thu, 23 April 2009 09:25 |
anjum.suri
Messages: 14 Registered: February 2008
|
Junior Member |
|
|
Thanks everyone for help
Could anyone please help?
I have written a small program that's actually working fine for me and extracting all the details I required. What code does is, it goes to all archivelog directories and see if archivelog backup was failed or successful
<<CODE>>
TMP_FILE='/ora/rman/scripts/tmp_chk.log'
chkbck ()
{
for i in `ls /ora/rman/logs/`;
do
find /ora/rman/logs/$i/backup_a*.log -mtime -1 2>/dev/null
done
}
for i in `chkbck`;
do
print $i | cut -d"_" -f3
print $i | cut -d"/" -f6
egrep -i 'Starting backup*' $i
egrep -i 'Finished backup*' $i
if egrep -i 'exit status [^0]' $i
then
print "Backup Failed"
else
print "Backup Successful"
fi
done > $TMP_FILE
<<CURRENT OUTPUT>>
ABC
backup_arch_ABC_22Apr09-155751.log
Starting backup at 22-APR-2009 15:57:58
Finished backup at 22-APR-2009 15:59:15
Backup Successful
XYZ
backup_arch_XYZ_22Apr09-160303.log
Starting backup at 22-APR-2009 16:03:15
Finished backup at 22-APR-2009 16:04:44
Backup Successful
Now, what I need is if I get this output in a email with proper headings and formatting.
<<DESIRED OUTPUT IN EMAIL>>
Database FileName Backup Start Backup End Status
--------- --------- ------------- ----------- -------
ABC backup_arch_ABC_22Apr09-155751.log 22-APR-2009 15:57:58 22-APR-2009 15:59:15 Backup Successful
XYZ backup_arch_XYZ_22Apr09-160303.log 22-APR-2009 16:03:15 22-APR-2009 16:04:44 Backup Successful
Could anyone please help me nicely formatting it?
|
|
|
|
|
|