- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell script for RMAN backup
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2013 08:28 AM - last edited on 09-16-2013 07:16 PM by Maiko-I
09-16-2013 08:28 AM - last edited on 09-16-2013 07:16 PM by Maiko-I
Shell script for rman backup
Hi All,
I am trying to configure rman backup to kick off through shell. here , I wrote following code with the help of exesiting script, but it seems that "if then else"is still an issue for me. Please offer your advise , as I tried to get this through , but all in vein. I am also looking to write this in such a manner , where in , if the database is down , then it simply send me a mail and if the the database is up , then execute the code , which I wrote here. thanks a lot in advance.
#!/usr/bin/sh . epmqa SID=EPMQA DATE=`date '+%m%d%y'` MAIL_LIST="aajitkumar@csc.com" LOG_DIR=/db/epmqa/export/rman LOG_FILE=${LOG_DIR}/${DATE}.log ps -ef | grep -i $SID | grep pmon if [ $? -eq 0 ] then rman connect target / spool log to '/db/epmqa/export/rman/$LOG_FILE' shutdown immediate ; startup mount; { backup database tag = 'wkly_cold_backup'; backup current controlfile tag = 'curr_ctl_file_bkp'; backup spfile tag = 'spfile_bkp'; } grep "ORA-" $LOG_FILE if [ $? -eq 0 ] then mailx -s 'Rman backup of $SID has some issues ' $MAIL_LIST < $LOG_FILE if grep "RMAN-" $LOG_FILE if [ $? -eq 0 ] then mailx -s 'Rman backup of $SID has some issues ' $MAIL_LIST < $LOG_FILE else mailx -s 'Rman backup of $SID completed successfully $MAIL_LIST < $LOG_FILE fi fi fi fi
rman2.sh[9]: Syntax error at line 27 : `else' is not expected.
P.S. This thread has been moved from HP-UX > General to HP-UX > languages. - Hp Forum Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2013 09:44 AM
09-16-2013 09:44 AM
Re: Shell script for RMAN backup
>"if then else"is still an issue for me.
It seems you have an "if" with nothing on the line.
It also helps if you have a consistent indentation style so we can see what matches.
>ps -ef | grep -i $SID | grep pmon
You should use "grep -q pmon" so you don't have this going to stdout.
>shutdown immediate ;
No need for semicolons.
{ ... }
No need for braces either.
>grep "ORA-" $LOG_FILE
Again, add -q to grep, here and below.
>if
>grep "RMAN-" $LOG_FILE
What was your intention with that "if"? Missing expression and "then".
>mailx -s 'Rman backup of $SID has some issues '
Why have a trailing space in the subject?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2013 10:00 AM
09-16-2013 10:00 AM
Re: Shell script for RMAN backup
First of all , thanks a lot. please find below my remarks.
>>It seems you have an "if" with nothing on the line.
It also helps if you have a consistent indentation style so we can see what matches.
I am using if condirtion to test pmon proces , if it is there , then I need to invoke rman utility , which
is a database backup utility
if [ $? -eq 0 ] then
rman connect target /
>ps -ef | grep -i $SID | grep pmon
>>You should use "grep -q pmon" so you don't have this going to stdout.
got that.
>>shutdown immediate ;
since , it is database command , i need to put ";" there.
No need for semicolons.
{ ... }
>> No need for braces either.
Are you refering LOG_FILE=${LOG_DIR}/${DATE}.log here.
>>grep "ORA-" $LOG_FILE
you meant grep -q "ORA-"
Again, add -q to grep, here and below.
>if
>grep "RMAN-" $LOG_FILE
>> What was your intention with that "if"? Missing expression and "then".
I need to grep ORA- or RMAN- from the log file output , if either of string found , then i need a mail stating backup has failed.
becuase. rman will throw rman- or ora- errors in that case.
>mailx -s 'Rman backup of $SID has some issues '
>> Why have a trailing space in the subject?
got that..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2013 10:42 AM
09-16-2013 10:42 AM
Re: Shell script for RMAN backup
>I am using if condition to test pmon process
The empty "if" doesn't do that.
>>shutdown immediate ;
>it is database command, I need to put ";" there.
Unless you are using a here doc, these are all shell commands. Perhaps you intended:
rman connect target / <<EOF
spool log to '/db/epmqa/export/rman/$LOG_FILE'
shutdown immediate ;
startup mount;
{
backup database tag = 'wkly_cold_backup';
backup current controlfile tag = 'curr_ctl_file_bkp';
backup spfile tag = 'spfile_bkp';
}
EOF
>> No need for braces either.
>Are you referring LOG_FILE=${LOG_DIR}/${DATE}.log here.
No the ones after: startup mount;
>you meant grep -q "ORA-"
Yes.
>I need to grep ORA- or RMAN- from the log file output, if either of string found
Then you should replace by one grep with -e:
grep -q -e "ORA-" -e "RMAN-" $LOG_FILE
if [ $? -eq 0 ]; then
mailx -s 'Rman backup of $SID has some issues' $MAIL_LIST < $LOG_FILE
else
Note the semicolon before the "then". You have that mistake in several places.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2013 06:26 AM
09-17-2013 06:26 AM
Re: Shell script for RMAN backup
Thanks a lot for your help here. I tried to create a script based on your inputs, but it seems , it's not coming out from rman. the backup part has beed done, but somehow , it's not exiting from rman. Please find below my comments. thanks in advance.
#!/usr/bin/sh . epmqa SID=EPMQA DATE=`date '+%m%d%y'` MAIL_LIST="aajitkumar@csc.com" LOG_DIR=/db/epmqa/export/rman LOG_FILE=${LOG_DIR}/${DATE}.log ps -ef | grep -i $SID | grep pmon if [ $? -eq 0 ]; then rman <<EOF connect target / spool log to '$LOG_FILE' shutdown immediate ; startup mount; { backup current controlfile tag = 'curr_ctl_file_bkp'; backup spfile tag = 'spfile_bkp'; } exit #### problem here EOF grep -q -e "ORA-" -e "RMAN-" $LOG_FILE ## Please explain this line if [ $? -eq 0 ]; then mailx -s 'Rman backup of $SID has errors ' $MAIL_LIST < $LOG_FILE else mailx -s 'Rman backup of $SID completed successfully' $MAIL_LIST < $LOG_FILE fi fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2013 12:37 AM
09-18-2013 12:37 AM
Re: Shell script for RMAN backup
Any inputs from your side Dennins. I even put the exit , but , it seems its not coming out from there.
Regards
Alok
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2013 06:10 AM
09-18-2013 06:10 AM
Re: Shell script for RMAN backup
Does the RMAN log file exist?
(according to your script, it should be at /db/epmqa/export/rman/<date>.log)
If it exists, what does it say?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2013 12:21 PM
09-18-2013 12:21 PM
Re: Shell script for RMAN backup
>grep -q -e "ORA-" -e "RMAN-" $LOG_FILE ## Please explain this line
Do a quiet search for either ORA- or RMAN- in $LOG_FILE and set the exit status.
>it's not exiting from rman.
You have typed that input into rman manually and it likes it? It's not waiting for you to type something?
But as Matti said, check the logfile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2013 06:53 AM
09-19-2013 06:53 AM
Re: Shell script for RMAN backup
Hi Dennis,
It says, backup finished. but, it's not coming out from rman. not sure, why. also, the process still active for some reason.
epmqa> tail -f /db/epmqa/export/rman/091913.log Starting backup at 19-SEP-13 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 19-SEP-13 channel ORA_DISK_1: finished piece 1 at 19-SEP-13 piece handle=/db/epmqa/export/rman/rman_EPMQA_1_18.rman tag=SPFILE_BKP comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 19-SEP-13 epmqa> ps -ef | grep rman oraepmqa 23428 23196 0 09:49:38 pts/0 0:00 sh -x rman2.sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2013 12:28 PM - edited 09-19-2013 12:30 PM
09-19-2013 12:28 PM - edited 09-19-2013 12:30 PM
Re: Shell script for RMAN backup
>the process still active for some reason.
What are the ancestors of that rman2.sh process?
ps -f -p 23428 -p 23196 # etc
If that process was put into the background and wants to write to stdout/stderr, it will hang.
Try redirecting that output:
rman <<EOF > rman.out 2>&1
Then cat that file on the end of $LOG_FILE:
...
EOF
cat rman.out >> $LOG_FILE
rm -f rman.out
Or just send the whole output from rman to $LOG_FILE and not use "spool log to".