Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Is it possible to automate RMAN Recovery with a bash script?

User_W2V5AJul 15 2021

Hi Everyone!
I am attempting to automate our Disaster Recovery plan as much as possible in an attempt to reduce our RTO/RPO.
One of the components of our DRP is restoring the oracle database using RMAN. Unfortunately my knowledge of database recovery is limited and hence I have made a test environment to experiment.
I am given a flash_recovery_area which contains dummy data and an instruction manual on how it is usually done manually by the database team.
With that, I constructed my first simple script:
LogFile="/home/oracle/rmanlog.log"
LogFile2="/home/oracle/rmantimelog.log"
SECONDS=0
rman target= / nocatalog LOG=$LogFile << EOF
run
{
STARTUP FORCE NOMOUNT;
RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;
configure device type 'SBT_TAPE' clear;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE clear;
CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' clear;
RESTORE DATABASE;
RECOVER DATABASE;
ALTER DATABASE OPEN RESETLOGS;
}
EOF
ELAPSED="Elapsed: $(($SECONDS / 3600))hrs $((($SECONDS / 60) % 60))min $(($SECONDS % 60))sec"
echo $ELAPSED > /home/oracle/rmantimelog.log
The problem with this script is that it works 4 or 5 times out of 10 tries and the time it doesn't work it gives the following error.
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 250124 and starting SCN of 19792842233
Obviously having a DRP that only works 4 or 5 times out of 10 isn't something anybody would want, so I tried another script which attempts to grab the SCN number and restore it again after the first try.
LogFile="/home/oracle/rmanlog.log"
LogFile2="/home/oracle/rmanlog2.log"
rman target= / nocatalog LOG=$LogFile << EOF
run
{
STARTUP FORCE NOMOUNT;
RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;
configure device type 'SBT_TAPE' clear;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE clear;
CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' clear;
RESTORE DATABASE;
RECOVER DATABASE;
}
EOF

if grep -q SCN "$LogFile"; then
SCN=$(grep -w "SCN" rmanlog.log | awk '{print $18}')
echo $SCN
rman target= / nocatalog LOG=$LogFile2 << EOF
run
{
STARTUP FORCE NOMOUNT;
RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;
configure device type 'SBT_TAPE' clear;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE SBT_TAPE clear;
CONFIGURE CHANNEL DEVICE TYPE 'SBT_TAPE' clear;
RESTORE DATABASE;
RECOVER DATABASE UNTIL SCN $SCN;
ALTER DATABASE OPEN RESETLOGS;
}
EOF
fi
However, I am told that the SCN changes every time rman is run and I am not too sure if I am even able to pass a bash variable into the RMAN running environment as the success rate of this script is the same as the first one.
I am hoping that anybody here can shed some light on whether or not this is possible as well as whether if this is even a good idea at all.
Thanks!

This post has been answered by EdStevens on Jul 16 2021
Jump to Answer

Comments

Processing

Post Details

Added on Jul 15 2021
9 comments
1,316 views