Sunday, 14 April 2013

Recovery from RMAN


I did this experiment where I took backup with BRTOOLS + RMAN and use it build a new system where restore and recovery done by plain RMAN Tool.

I didn’t find any document for this on portal , so I am creating this doc for those who wants to do this experiment..

If anyone knows the doc from SAP on this topics please let me know...

Take a backup on Source server / DB


Init profile name in dbs: BR_RMAN_initMID.sap

IMP parameters:

backup_mode = full
backup_dev_type = disk
disk_copy_cmd = rman_set

Backup Location: /nasbackup/MID_BR_RMAN_FULL

Backup command:
brbackup -p BR_RMAN_initMID.sap -d disk -t online -m full -k yes -e 0 -l E


>>>>>>>>> Backup Part Ends Here <<<<<<<<<<<<<<<<

On Target Server


Please use a test server for doing this experiment.

Scenario: Different Host, Different DB_NAME, can have Different datafile location, homogeneous system (same OS Family)
Source Info:
DB_NAME=MID
Datafile path : /oracle/MID/sapdata1-4

Target Info:
DB_NAME=T01
Datafile path : /oracle/T01/sapdata1-4  (we can have anything here, as we are using RMAN for restore.. its easy to do it)

Step 1) IF you old test database on server, drop that test database including the datafiles and content.
Step 2) Note that at first we have to restore / recover db as is (with same old db_name=MID but different paths) then we change database name to make it T01.. read this line couple of times..

Important parameters in initfile:

db_name = MID
control_files = (/oracle/T01/origlogA/cntrl/cntrlMID.dbf, /oracle/T01/origlogB/cntrl/cntrlMID.dbf, /oracle/T01/sapdata1/cntrl/cntrlMID.dbf)
background_dump_dest = /oracle/T01/saptrace/background
user_dump_dest       = /oracle/T01/saptrace/usertrace
core_dump_dest       = /oracle/T01/saptrace/background
log_archive_dest     = /oracle/T01/oraarch/T01arch

Step 2: Make thesource db backup available to target system
Here our backup is copied on : /oracle/T01/sapdata8/MID_BR_RMAN_FULL

Note that I use sapdata8 as it was empty.. none of my datafile is going to be restored on sapdata8.. You can copy it anywhere as per availability.

Step 3: Restore Process

Start DB in NOMOUNT with changed initMID.ora or initT01.ora (SID in initfile or ORACLE_SID env parameter is not involved yet in this)

SQL > startup nomount;

You can provide pfile path also, here I am sure that I have only one initMID.ora file and that is the correct one. (Still my ORACLE_SID is MID so this command will choose initMID.ora)

Restore Control file:
BRBACKUP takes the SnapShot backup if controfile so just copy the controlfile from backup to controlfile location.

cp -pv cntrlMID.dbf /oracle/T01/origlogA/cntrl/
cp -pv cntrlMID.dbf /oracle/T01/origlogB/cntrl/
cp -pv cntrlMID.dbf /oracle/T01/sapdata1/cntrl/

Then Mount DB
SQL > alter database mount;

Note: As we copied source controlfile, it will have all backup related path info..so while restoring it will keep on looking for all those backup source path and archvielog paths.. At this point controlfile do not have any info of new backup location.

So, I choose to clear all those stuff from controlfile and catalog new location where backup is available.


RMAN> list backup;   shows backup from source.. Clean it up
RMAN> list archivelog all;
RMAN> crosscheck backup
RMAN> delete expired backup;
RMAN> delete expired archivelog all;


Now add new info to control file for copied backup and archives.
RMAN> catalog start with '/oracle/T01/sapdata8/MID_BR_RMAN_FULL';

Make sure that you have desired directory structure created.


Restore Script:

run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
SET NEWNAME FOR DATAFILE 1  to '/oracle/T01/sapdata1/system_1/system.data1' ;
SET NEWNAME FOR DATAFILE 2  to '/oracle/T01/sapdata1/undo_1/undo.data1' ;
SET NEWNAME FOR DATAFILE 3  to '/oracle/T01/sapdata1/sysaux_1/sysaux.data1' ;
SET NEWNAME FOR DATAFILE 4  to '/oracle/T01/sapdata2/sr3_1/sr3.data1' ;
SET NEWNAME FOR DATAFILE 5  to '/oracle/T01/sapdata2/sr3_2/sr3.data2' ;
SET NEWNAME FOR DATAFILE 6  to '/oracle/T01/sapdata2/sr3_3/sr3.data3' ;
SET NEWNAME FOR DATAFILE 7  to '/oracle/T01/sapdata2/sr3_4/sr3.data4' ;
SET NEWNAME FOR DATAFILE 8  to '/oracle/T01/sapdata3/sr3700_1/sr3700.data1' ;
SET NEWNAME FOR DATAFILE 9  to '/oracle/T01/sapdata3/sr3700_2/sr3700.data2' ;
SET NEWNAME FOR DATAFILE 10  to '/oracle/T01/sapdata3/sr3700_3/sr3700.data3' ;
SET NEWNAME FOR DATAFILE 11  to '/oracle/T01/sapdata3/sr3700_4/sr3700.data4' ;
SET NEWNAME FOR DATAFILE 12  to '/oracle/T01/sapdata4/sr3usr_1/sr3usr.data1' ;
SET NEWNAME FOR DATAFILE 13  to '/oracle/T01/sapdata4/sr3db_1/sr3db.data1' ;
SET NEWNAME FOR DATAFILE 14  to '/oracle/T01/sapdata4/sr3db_2/sr3db.data2' ;
SET NEWNAME FOR DATAFILE 15  to '/oracle/T01/sapdata4/sr3db_3/sr3db.data3' ;
SET NEWNAME FOR DATAFILE 16  to '/oracle/T01/sapdata2/sr3_5/sr3.data5' ;
SET NEWNAME FOR DATAFILE 17  to '/oracle/T01/sapdata2/sr3_6/sr3.data6' ;
SET NEWNAME FOR DATAFILE 18  to '/oracle/T01/sapdata2/sr3_7/sr3.data7' ;
SET NEWNAME FOR DATAFILE 19  to '/oracle/T01/sapdata3/sr3700_5/sr3700.data5' ;
SET NEWNAME FOR DATAFILE 20  to '/oracle/T01/sapdata3/sr3700_6/sr3700.data6' ;
SET NEWNAME FOR DATAFILE 21  to '/oracle/T01/sapdata3/sr3700_7/sr3700.data7' ;
SET NEWNAME FOR DATAFILE 22  to '/oracle/T01/sapdata3/sr3700_8/sr3700.data8' ;
SET NEWNAME FOR DATAFILE 23  to '/oracle/T01/sapdata1/system_2/system.data2' ;
SET NEWNAME FOR DATAFILE 24  to '/oracle/T01/sapdata3/sr3700_9/sr3700.data9' ;
SET NEWNAME FOR DATAFILE 25  to '/oracle/T01/sapdata3/sr3700_10/sr3700.data10' ;
SET NEWNAME FOR DATAFILE 26  to '/oracle/T01/sapdata3/sr3700_11/sr3700.data11' ;
SET NEWNAME FOR DATAFILE 27  to '/oracle/T01/sapdata3/sr3700_12/sr3700.data12' ;
SET NEWNAME FOR DATAFILE 28  to '/oracle/T01/sapdata3/sr3700_13/sr3700.data13' ;
SET NEWNAME FOR DATAFILE 29  to '/oracle/T01/sapdata3/sr3700_14/sr3700.data14' ;
SET NEWNAME FOR DATAFILE 30  to '/oracle/T01/sapdata2/sr3_8/sr3.data8' ;
SET NEWNAME FOR DATAFILE 31  to '/oracle/T01/sapdata2/sr3_9/sr3.data9' ;
SET NEWNAME FOR DATAFILE 32  to '/oracle/T01/sapdata2/sr3_10/sr3.data10' ;
SET NEWNAME FOR DATAFILE 33  to '/oracle/T01/sapdata3/sr3700_15/sr3700.data15' ;
SET NEWNAME FOR DATAFILE 34  to '/oracle/T01/sapdata3/sr3700_16/sr3700.data16' ;
SET NEWNAME FOR DATAFILE 35  to '/oracle/T01/sapdata3/sr3700_17/sr3700.data17' ;
SET NEWNAME FOR DATAFILE 36  to '/oracle/T01/sapdata3/sr3700_18/sr3700.data18' ;
SET NEWNAME FOR TEMPFILE 1  to '/oracle/MID/sapdata1/temp_1/temp.data1' ;

set until sequence 5325 thread 1;
restore database;
switch datafile all;
}

Note that: I am doing Point time Recovery
Set until clause may not be neccesary while doing RESTORE, but still I use it.


Step 4) Recover the Database
run {
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
set until sequence 5325 thread 1;
recover database;
}


Step 5 ) Rename Online Redolog files

alter database rename file '/oracle/MID/origlogA/log_g11m1.dbf' to '/oracle/T01/origlogA/log_g11m1.dbf';
alter database rename file '/oracle/MID/mirrlogA/log_g11m2.dbf' to '/oracle/T01/mirrlogA/log_g11m2.dbf';
alter database rename file '/oracle/MID/origlogB/log_g12m1.dbf' to '/oracle/T01/origlogB/log_g12m1.dbf';
alter database rename file '/oracle/MID/mirrlogB/log_g12m2.dbf' to '/oracle/T01/mirrlogB/log_g12m2.dbf';
alter database rename file '/oracle/MID/origlogA/log_g13m1.dbf' to '/oracle/T01/origlogA/log_g13m1.dbf';
alter database rename file '/oracle/MID/mirrlogA/log_g13m2.dbf' to '/oracle/T01/mirrlogA/log_g13m2.dbf';
alter database rename file '/oracle/MID/origlogB/log_g14m1.dbf' to '/oracle/T01/origlogB/log_g14m1.dbf';
alter database rename file '/oracle/MID/mirrlogB/log_g14m2.dbf' to '/oracle/T01/mirrlogB/log_g14m2.dbf';

Step 6) Open DB with RESETLOGS

RMAN > alter database open resetlogs.

Step 7) Create a new temp tablespace, make it default and drop old one.

SQL> create temporary tablespace PSAPTEMP2 tempfile '/oracle/T01/sapdata1/temp_1/temp.data1' size 4096m;
SQL> alter database default temporary tablespace PSAPTEMP2;
SQL> drop tablespace PSAPTEMP including contents and datafiles;

Now database is OPEN in R/W mode (as normal DB).. As of now DB_name is MID and ORACLE_SID is T01

Now we have to change the db name.. there are two methods to do this..

Step 7) Change DB Name
You can Oracle nid tool to chnage database name, Here I am doing it by creating controlfile.

considering your db in open now.
Take a controlfile backup to trace

SQL> alter database backup controlfile to trace as '/oracle/T01/manual_ctl.sql';

Then Shutdown database

SQL>shut immediate;

Now DB is down, go to each controlfile location and move controlfile to new name..
So that in next step it can create new controlfile for T01.

krqat01:orat01 76> pwd
/oracle/T01/origlogB/cntrl

krqat01:orat01 77> ls
cntrlMID.dbf
krqat01:orat01 78> mv cntrlMID.dbf cntrlMID.dbf.old
krqat01:orat01 79> ls
cntrlMID.dbf.old

Now edit the controlfile trace textfile. Here we will choose second option.
  1. i.e. RESETLOG
edit file to have change like this.

-----------------------------------------------------------------------------------------------------------
CREATE CONTROLFILE SET DATABASE "T01" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 255
    MAXLOGMEMBERS 3
    MAXDATAFILES 254
    MAXINSTANCES 50
    MAXLOGHISTORY 1168
.
..
'/oracle/T01/sapdata3/sr3700_17/sr3700.data17',
'/oracle/T01/sapdata3/sr3700_18/sr3700.data18'
CHARACTER SET UTF8
;
-------------------------------------------------------------------------------------------------------------

Note that Change SET keyword from REUSE.

Note : Now we have to change db_name in initT01.ora to new SID i.e db_name=T01

Note: We have removed the “startup nomount” from edited controlfile trace file.

So, now start instance in nomount mode

SQL> startup nomount;

SQL> @manual_ctl.sql
Control file created.

SQL> alter database open resetlogs;

Database altered.

SQL> show parameter db_name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      T01

>>>>>>>>>>>>>>> Doc Ends Here <<<<<<<<<<<<<

No comments:

Post a Comment