Thursday, October 15, 2009

How to restore DB from tape if DBID has been changed

You are requested to restore a database (into another one) from RMAN backup on tape which was done 2 month ago. You requested tape from your storage company, you have your backup copied over to your server - if that is your preference. And all of a sudden you realize that DBID has been changed AFTER you took your backup - say your database has been refreshed from production and this is a part of the process.

No problem! Just do that:

Eestore the controlfile, then the backup as follows:
RMAN> startup nomount force;
RMAN> restore controlfile from '/db/backup/MYDB/25jul09/c-3431719427-20090723-00';
RMAN> alter database mount;
This should mount the controlfile with the old DBID

Now you may proceed with the database restore - catalog you backup pieces, run restore & recover, apply archive logs (from the same tape) if necessary...

Script to restart database if down

#!/usr/bin/sh
# By GregZ 10/13/2009 to check DB status
##set -v
export ORACLE_HOME=/oracle/app/oracle/product/10.2.0
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=CRBURN
greg=gregz@gregzllc.com
#*************************************************************
# Test to see if Oracle is up...
#*************************************************************
$ORACLE_HOME/bin/sqlplus -s /< /tmp/check_$ORACLE_SID.ora
select * from v\$database;
quit
EOF
#*************************************************************
# If not, restart and e-mail...
#*************************************************************
check_stat=`cat /tmp/check_$ORACLE_SID.ora I grep -i error Iwc -l`;
oracle_num=`expr $check_stat`
echo $oracle_num
if [ $oracle_num -ne 0 ]
then
echo "$ORACLE_SID is down!" I mailx -s "$ORACLE_SID is down!" $greg
sqlplus "/ as sysdba" < /tmp/check_$ORACLE_SID.ora
startup
select * from v\$database;
quit
EOF1
check_stat=`cat /tmp/check_$ORACLE_SID.ora I grep -i error I wc -l`;
oracle_num=`expr $check_stat`
###echo $oracle_num
if [ $oracle_num -eq 0 ]
then
echo "$ORACLE_SID is brought up" I mailx -s "$ORACLE_SID is back up" $greg
fi
##else
## echo "$ORACLE_SID is up" I mailx -s "$ORACLE_SID is up" $greg
fi
exit 0