Friday, January 11, 2013

RMAN Cold BACKUP & RMAN RESTORE Steps

RMAN Cold Backup (compressed backup) script

Below is the simple RMAN script to backup & restore database without any hurdles.

In below script, you need to replace Text which are in Red with your environment details, for example my ORACLE_SID is ORCL1, you need to replace with your DB details.
Note: Here my Database is on ASM diskgroup +DATADG
I used the parallelism 32, you can try with less or more depending on your DB size and compute.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$backup.sh 
PATH=$PATH:$HOME/bin
ORACLE_BASE=/u01/app/oracle
export ORACLE_BASE
ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/dbhome_1
export ORACLE_HOME
ORACLE_SID=ORCL1
export ORACLE_SID
ORACLE_UNQNAME=ORCL
export ORACLE_UNQNAME
PATH=$HOME/bin:$ORACLE_HOME/bin:$PATH
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
#mkdir -p /BACKUP/RMAN/log                             #Creating Backup directories to place the backup
#mkdir -p /BACKUP/RMAN/ORCL/controlfile       #Remove comments if directories doesn't exist.
#mkdir -p /BACKUP/RMAN/ORCL/pfile
#mkdir -p /BACKUP/RMAN/ORCL/RMANFullBkp

rman target / log=/BACKUP/RMAN/log/ORCL`date +%d%m%Y`.log <<EOF

configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/BACKUP/RMAN/ORCL/controlfile/%F.ctl';
CONFIGURE DEVICE TYPE DISK PARALLELISM 32 BACKUP TYPE TO COMPRESSED BACKUPSET;
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/BACKUP/RMAN/ORCL/RMANFullBkp/cold_bkp_%U';

sql "create pfile=''/BACKUP/RMAN/ORCL/pfile/pfileORCL`date +%d%m%Y`.ora'' from spfile";
sql 'alter system checkpoint';
sql 'alter system checkpoint';
shutdown immediate;
startup;
sql 'alter system checkpoint';
shutdown immediate;
startup mount;
backup as compressed backupset database;
alter database open;
report schema;
exit;
EOF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Just run the above script, (./backup.sh) it will shutdown and bring the database to mount state and after backup completion brings back the DB to open state. You can watch the log from other terminal from  /BACKUP/RMAN/log/ dir.  

Restore script:

Assumption : Same ASM disk group name +DATADG (in this case) is already present and respective directories are already created inside +DATADG (In this case +DATADG/ORCL/DATAFILE etc, if it is not present you need to manually create it).

Again replace Text which are in red with appropriate value from backup which you took. 

my $restore.sh script looks as below
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$restore.sh
run
{
#shutdown immediate;
startup pfile='/BACKUP/RMAN/ORCL/pfile/pfileORCL11122012.ora' nomount;
restore spfile from '/BACKUP/RMAN/ORCL/controlfile/c-838456344-20130104-00.ctl';
shutdown immediate;
startup nomount;
restore controlfile from '/BACKUP/RMAN/ORCL/controlfile/c-838456344-20130104-00.ctl';
alter database mount;
restore database;
alter database open resetlogs;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run the restore script as below from oracle user.  
$rman target / 
rman>@restore.sh


No comments:

Post a Comment