Tuesday 27 December 2011

RMAN Full Database Backups & Restoration in scripts

Backups from source:

$pwd
/home/oracle

create a scripts for taking backup details:
$view cold_backup.cmd

connect catalog username/password@catdbname
run
{
allocate channel t1 type 'SBT_TAPE' parms 'ENV=(NSR_SERVER=hsun10, NSR_CLIENT=hsun102)';
allocate channel t2 type 'SBT_TAPE' parms 'ENV=(NSR_SERVER=hsun10, NSR_CLIENT=hsun102)';
allocate channel t3 type 'SBT_TAPE' parms 'ENV=(NSR_SERVER=hsun10, NSR_CLIENT=hsun102)';
backup database plus archivelog filesperset=3 tag='PRODDB_HSUN102_COLD_BACKUP';
backup current controlfile tag='PRODDB_HSUN102_COLD_CONTROL';
release channel t1;
release channel t2;
release channel t3;
}
exit

create a master scripts(cold_backup.sh)
$view cold_backup.sh
rman target / @cold_backup.cmd log="cold_backup.log"

then run the Master scripts in background:
$nohup cold_backup.sh &

Now the backup process will start automatically....
check the backup process in log files "cold_backup.log"
$tail -100f cold_backup.log

                      *****************


Restore into Target:

Step 1: Restore control file from backup tag "PRODDB_HSUN102_COLD_CONTROL"

connect target /
connect catalog username/password@catdbname
run{
allocate channel t1 type 'SBT_TAPE' parms 'ENV=(NSR_SERVER=hsun10,NSR_CLIENT=hsun102)';
restore controlfile to '/tmp/control01_backup.ctl' from TAG=PROD082_HSUN102_COLD_CONTROL;
release channel t1;
}

Step 2: Restore datafile "system" with new location:
run {
allocate channel t1 type 'SBT_TAPE' parms 'ENV=(NSR_SERVER=hsun10, NSR_CLIENT=hsun102)';
set newname for datafile 1 to '/opt/oracle/oradata/PROD082/data1/system_01.dbf';
restore datafile 1;
switch datafile 1;
release channel t1;
}


Step 2: Restore other datafiles :

Create a master file to restore all other datafiles
$view restore.sh
rman target / @restore1.sh log="restore1.log"


then create restore1.sh with the details like below:
 $view restore1.sh
run {

allocate channel t1 type 'SBT_TAPE' parms 'ENV=(NSR_SERVER=hsun10, NSR_CLIENT=hsun102)';
set newname for datafile 2 to '/opt/oracle/oradata/PROD082/data1/undo_space_01.dbf';
set newname for datafile 3 to '/opt/oracle/oradata/PROD082/data1/sysaux_01.dbf';
set newname for datafile 4 to '/opt/oracle/oradata/PROD082/data1/data_01.dbf';
set newname for datafile 5 to '/opt/oracle/oradata/PROD082/data1/indexes_01.dbf';
set newname for datafile 6 to '/opt/oracle/oradata/PROD082/data1/odm_01.dbf';
set newname for datafile 7 to '/opt/oracle/oradata/PROD082/data1/ctxsys_01.dbf';
set newname for datafile 8 to '/opt/oracle/oradata/PROD082/data1/xdb_01.dbf';
set newname for datafile 9 to '/opt/oracle/oradata/PROD082/data1/SYSUSERIDX_02.DBF';
set newname for datafile 10 to '/opt/oracle/oradata/PROD082/data1/SYSUSERIDX.DBF';
set newname for datafile 11 to '/opt/oracle/oradata/PROD082/data1/SYSUSER_02.DBF';
set newname for datafile 12 to '/opt/oracle/oradata/PROD082/data1/SYSUSER.DBF';
restore datafile 2;
restore datafile 3;
restore datafile 4;
restore datafile 5;
restore datafile 6;
restore datafile 7;
restore datafile 8;
restore datafile 9;
restore datafile 10;
restore datafile 11;
restore datafile 12;
switch datafile 2;
switch datafile 3;
switch datafile 4;
switch datafile 5;
switch datafile 6;
switch datafile 7;
switch datafile 8;
switch datafile 9;
switch datafile 10;
switch datafile 11;
switch datafile 12;
release channel t1;
}

if you required you can create more then part of datafiles like restore2.sh, restore3.sh

$view restore2.sh

run {
allocate channel t1 type 'SBT_TAPE' parms 'ENV=(NSR_SERVER=hsun10, NSR_CLIENT=hsun102)';
set newname for datafile 13 to '/opt/oracle/oradata/PROD082/data1/data_013.dbf';
set newname for datafile 14 to '/opt/oracle/oradata/PROD082/data1/data_014.dbf';
set newname for datafile 15 to '/opt/oracle/oradata/PROD082/data1/data_015.dbf';
set newname for datafile 16 to '/opt/oracle/oradata/PROD082/data1/data_016.dbf';
restore datafile 13;
restore datafile 14;
restore datafile 15;
restore datafile 16;
switch datafile 13;
switch datafile 14;
switch datafile 15;
switch datafile 16;
release channel t1;
}

Then start running the master restoration script(restore.sh) in background:

$nohup restore.sh &
Now it will start restoration automatically, you can monitor the process in "restore1.log"

$tail -100f restore1.log

No comments:

Post a Comment