RMAN COLD BACKUP AND RESTORE (11GR2)
===========================================================================================================================
Simple RMAN script to take cold database backup: (Depending on Situation)
===========================================================================================================================
To Take RMAN cold database backup, your Database should be in mount status, Which can be noticed from below scipt.
We are not using the pfile backup, but in case you want you can add that step in script as well
Before Run step in RMAN
sql “create pfile=”/BACKUP/PROD/pfile`date +%d%m%Y`.ora” from spfile”;
mkdir -p /backup/mtandonmt/cold_bk
mtandon@mt77007:mtandonmt:/backup/mtandonmt/cold_bk $ more rman_cold_bk_after_DB_refresh.20130807
. /var/opt/oracle/bin/mtandonmt.env ## Please set the environment variable or set it manually
LOG_DIR=/export/home/mtandon
LOG_FILE='rman_cold_bk_20130807.log' ### OR rman target / log=/BACKUP/PROD/log/PROD`date +%d%m%Y`.log <sql ‘alter system checkpoint';
rman log=$LOG_FILE append MSGNO <
connect target sys/XXXXX@mtandonmt;
##sql “create pfile=”/backup/mtandonmt/cold_bk/pfile`date +%d%m%Y`.ora” from spfile”; ## We are not using here
run
{
shutdown immediate;
startup mount;
allocate channel d1 type DISK format '/backup/mtandonmt/cold_bk/cold_bk_%n_%U';
set limit channel d1 kbytes = 33554432; # Limit to 32G
allocate channel d2 type DISK format '/backup/mtandonmt/cold_bk/cold_bk_%n_%U';
set limit channel d2 kbytes = 33554432; # Limit to 32G
allocate channel d3 type DISK format '/backup/mtandonmt/cold_bk/cold_bk_%n_%U';
set limit channel d3 kbytes = 33554432; # Limit to 32G
allocate channel d4 type DISK format '/backup/mtandonmt/cold_bk/cold_bk_%n_%U';
set limit channel d4 kbytes = 33554432; # Limit to 32G
BACKUP AS COMPRESSED BACKUPSET DATABASE;
BACKUP CURRENT CONTROLFILE FORMAT '/backup/mtandonmt/cold_bk/cold_bk_cntrl_%s_%p_%t';
release channel d1;
release channel d2;
release channel d3;
release channel d4;
alter database open;
}
EOF
ERROR_CODE=$?
if [ "$ERROR_CODE" != 0 ]; then
echo "" >>$LOG_FILE
date >>$LOG_FILE
echo "*** ERROR ***" >>$LOG_FILE
echo "*** Problem in DB Duplicate" >>$LOG_FILE
echo "" >>$LOG_FILE
exit $ERROR_CODE;
fi
echo 'End DB cold_bk ' $(date) >>$LOG_FILE
============================================================================================================================
#####
## SETTING THE ENV or user above with location
##export ORACLE_HOME=/m01/app/oracle/product/11.2.0
###export ORACLE_SID=PROD
##export PATH=$ORACLE_HOME/bin:$PATH
##export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
script execution:
mtandon@mt77007:mtandonmt:/backup/mtandonmt/cold_bk $nohup /backup/mtandonmt/cold_bk/rman_cold_bk_DB_refresh.20130807 &
Do the Tail on it to see the logs while it's in Progress
tail -f rman_cold_bk_20130807.log
RMAN-08031: released channel: d1
RMAN-08031: released channel: d2
RMAN-08031: released channel: d3
RMAN-08031: released channel: d4
RMAN-06400: database opened
RMAN>
RMAN>
Recovery Manager complete.
So we have the Cold backup done and your database is back in Open status
===========================================================================================================================
Simple RMAN script to RESTORE DATABASE:
============================================================================================================================
Make sure that rman backup is mounted on target system and necessary directories configured same as source system or you are doing the restore back after testing by Application
Please note we are also restoring the control file.
$more restore_rman_cold_bk.20130907
LOG_DIR=/export/home/mtandon
LOG_FILE='restore_rman_cold_bk_20130907.log'
rman log=$LOG_FILE append MSGNO <
connect target sys/XXXXXX@mtandonmt;
run
{
startup nomount; ## OR startup pfile=’/backup/mtandonmt/cold_bk/pfilexxxxxxx.ora’ nomount; Not used
restore controlfile from '/backup/mtandonmt/cold_bk/cold_bk_cntrl_XX_X_XXXXXXXX';
alter database mount;
allocate channel d01 type disk;
allocate channel d02 type disk;
allocate channel d03 type disk;
allocate channel d04 type disk;
allocate channel d05 type disk;
allocate channel d06 type disk;
allocate channel d07 type disk;
allocate channel d08 type disk;
restore database;
alter database open resetlogs;
}
EOF
ERROR_CODE=$?
if [ "$ERROR_CODE" != 0 ]; then
echo "" >>$LOG_FILE
date >>$LOG_FILE
echo "*** ERROR ***" >>$LOG_FILE
echo "*** Problem in DB Duplicate" >>$LOG_FILE
echo "" >>$LOG_FILE
exit $ERROR_CODE;
fi
echo 'End DB cold_bk ' $(date) >>$LOG_FILE
=================================================================================
script execution:
mtandon@mt77007:mtandonmt:/backup/mtandonmt/cold_bk $nohup /backup/mtandonmt/cold_bk/restore_rman_cold_bk.20130907 &
Do the Tail on it to see the logs while it's in Progress
tail -f restore_cold_bk_20130807.log
Again, depending on Size and Server busy it will take time to restore
At the end of the script completion you will see the message like this
RMAN-08031: released channel: d01
RMAN-08031: released channel: d02
RMAN-08031: released channel: d03
RMAN-08031: released channel: d04
RMAN-08031: released channel: d05
RMAN-08031: released channel: d06
RMAN-08031: released channel: d07
RMAN-08031: released channel: d08
RMAN>
RMAN>
Recovery Manager complete.
========================================================================
Keep things Simple -- Enjoy
No comments:
Post a Comment