RMAN restore backup, from tape to another server

A good exercise to verify that a backups made it correctly, is prepare a script that does a restoring on demand to another server (frequently in preproducction environment)

I tell a restoring and not a clone (something really amazing that you can clone a DB without stop it until current time), because the cloned needs the origin DB (surely production) has to remain in open state and in case of disaster this is not the scenario.

The restoring show here was made without external RMAN catalog (is using only information of controlfile as catalog), this forces to have enable the option:

Source   
CONFIGURE CONTROLFILE AUTOBACKUP ON;

Enabled during the DB production backup and to know the dbid (it’s possible know directly login in RMAN of origin DB).

The main problem appears when you try to restore a DB and not specified correctly until what date time you want to restore. If we work to date and there have been frequent backups or backup is a few hours ago, you may not be successful and indicates that some datafiles RMAN we need more recovery.

For solve this problem the best is to request the maximum of sequence that we have in the controlfile recently restored. This we can to get with (file “get_sequence.sql”):

Source   
SELECT max(SEQUENCE#) as secuencia from v$archived_log;
exit

That during the execution of the next script is called (file “restore_rman.sh”):

Source   
#!/bin/bash
export ORACLE_HOME=/oracle/u02/app/oracle/product/10.2.0/db_1
export ORACLE_BASE=/oracle/u02/app/oracle
export ORACLE_SID=FPYS
export PATH=$ORACLE_HOME/bin:$PATH
export TNS_ADMIN=$ORACLE_HOME/network/admin
echo `date`
echo "##### Stop db"
sqlplus / as sysdba << EOF
shutdown abort;
EOF
echo `date`
echo "##### Remove all datafiles of DB "
rm /oracle/u03/datafiles/FPYS/*
rm /oracle/u03/archivelog/fpys/*
echo `date`
echo "##### Start nomount, restore controlfile and mount"
rman target=/ nocatalog << EOF
set dbid=2213028659;
run {
startup nomount;
allocate channel t1 type 'SBT_TAPE';
send 'NB_ORA_POLICY=P_Oracle_Full_Semanal, NB_ORA_SERV=serverfpsbackup,NB_ORA_CLIENT=FPYSS53';
restore controlfile from autobackup;
alter database mount;
}
EOF
echo `date`
echo "##### Search sequence number"
secuencia=`sqlplus / as sysdba @/home/oracle/scripts/restauracion_prod/get_sequence.sql | grep SECUENCIA -A2 | tail -1 | awk {'print $1'}`
echo $secuencia
echo `date`
echo "##### Restore DB"
rman nocatalog target=/ log=/home/oracle/scripts/restauracion_prod/restaura.rman.log << EOF
run {
allocate channel t1 type 'SBT_TAPE';
send 'NB_ORA_POLICY=P_Oracle_Full_Semanal, NB_ORA_SERV=serverfpsbackup,NB_ORA_CLIENT=FPYSS53';
SET UNTIL SEQUENCE=$secuencia;
restore database;
recover database;
}
EOF
echo `date`
echo "##### Change BD to noarchivelog mode and opened with resetlogs"
sqlplus / as sysdba << EOF
alter database noarchivelog;
alter database open resetlogs;
EOF
echo `date`
echo "##### Restart DB for to get a clear alert log and redimension of tablespace TEMP"
sqlplus / as sysdba << EOF
shutdown immediate;
startup;
ALTER DATABASE TEMPFILE '/oracle/u03/datafiles/FPYS/temp01.dbf' RESIZE 1024M;
EOF
rm /oracle/u03/archivelog/fpys/*

This script do:

  1. Stop DB with abort.
  2. Remove all datafiles from destiny, in this case all files from /oracle/u03/datafiles/FPYS
  3. Start DB in nomount, restore controlfile and mount
  4. Search the last sequence number inside restored controlfile.
  5. Restore and recover DB.
  6. Change BD to noarchivelog mode and opened with resetlogs
  7. Resize TEMP tablespace. This is necessary because TEMP tablespace never is backed, simply is created one with 20M.

Of course the destiny server must to have password file and parameters, created for the SID we are working.

This is the safest way I have found to verify that a backup is correct and everything is configured correctly, ensure that we are able to restore on another machine, this is necessary because some backup systems must be parameterized to allow restorations made in a different machine (eg NetBackup).

In case of disaster have everything approved and it is important to avoid “tense” situations.

Leave a Reply