Home » Infrastructure » Unix » UNIX script to check archivelog backup (Any)
UNIX script to check archivelog backup [message #394123] Wed, 25 March 2009 14:57 Go to next message
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 #394129 is a reply to message #394123] Wed, 25 March 2009 15:07 Go to previous messageGo to next message
Michel Cadot
Messages: 68617
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
I am very new to programming/scripting so need some help from UNIX gurus;

But this is not a Unix forum, this is an Oracle forum, so you will more likely find Oracle gurus than Unix gurus.
Maybe you should post your question to a Unix forum.

Regards
Michel
Re: UNIX script to check archivelog backup [message #394135 is a reply to message #394129] Wed, 25 March 2009 15:23 Go to previous messageGo to next message
anjum.suri
Messages: 14
Registered: February 2008
Junior Member
I have posted there as well; I understand problem is more related to UNIX but still its more like Oracle UNIX combination
Re: UNIX script to check archivelog backup [message #394138 is a reply to message #394123] Wed, 25 March 2009 15:37 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
>> I want a report to be emailed to me with details of which databases archivelog backups failed and for which they went successful
That means you have to store the "data" somewhere.
"data" here is fail/success.
This could be very simple.
Read the files, get database info and exit status and append (redirect) to a another file. Do this in a loop.
At end, this appended file will have something like this. Just mail it to yourself.
dbname1,status
dbname2,status
Re: UNIX script to check archivelog backup [message #394139 is a reply to message #394129] Wed, 25 March 2009 15:42 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Post a sample file to work with, with patterns to identify dbinfo and exit status.
Re: UNIX script to check archivelog backup [message #394367 is a reply to message #394123] Thu, 26 March 2009 12:25 Go to previous messageGo to next message
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 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
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 Wink.

missed the files like
>>/ora/rman/logs/ORADB1P/backup_arch_ORADB1P_04Sep07-07:42:22.log

Just
instead of
>>ls -lart *DBA*
use
ls -lart *.log

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 Go to previous messageGo to next message
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?
Re: UNIX script to check archivelog backup [message #399699 is a reply to message #394123] Thu, 23 April 2009 09:26 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Could anyone please help me nicely formatting it?
How is formatting email related to Oracle?
Re: UNIX script to check archivelog backup [message #399700 is a reply to message #399698] Thu, 23 April 2009 09:29 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
>>Could anyone please help me nicely formatting it?
It would be much easier to generate the report in the format you want.
YOu can just create headings in the loop. It is been already explained for you.
Re: UNIX script to check archivelog backup [message #399706 is a reply to message #394123] Thu, 23 April 2009 10:53 Go to previous message
anjum.suri
Messages: 14
Registered: February 2008
Junior Member
I am sorry Mahesh; I didnt get you; could you please provide an example; I hope I will pick it up from there....

Thanks
Previous Topic: unix shell script
Next Topic: FTP in UNIX Shell scripting
Goto Forum:
  


Current Time: Tue Mar 19 02:00:46 CDT 2024