Sunday, June 22, 2014

Step by Step procedure to restore database to another host using RMAN

Before going to restore the database, we need to install the binaries for Oracle database and ASM (if used for storage).  Also, create the required directories like adump,bdump, cdump, pfile, redo log files, etc. The scenario is as follows.

Ø  The database is old server got crashed and this was using Server Parameter file (SPfile)
Ø  We have another fresh server with media manager installed to make the facility restore from media manager.
Ø  The database name of the new db should be as old database which got crashed.
Ø  We have all recoverable backups on tape of all datafiles.
Ø  We have backups of all archived logs to recover the datafiles.
Ø  We have controlfile and spfile backup available on tape.

1.       To restore a database to another host using RMAN
Enter the following commands to obtain the db_id value (database ID) of the database you want to restore from the RMAN catalog:

sqlplus <rman user>/<rman password>@<rman service>

SQL> select db_key, db_id, bs_key, recid, stamp, backup_type, start_time, status from rc_backup_set;
Identify the db_id value corresponding to the database you want to restore.

If you are not able to access rman catalog, the another method is to find the db id from the controlfile autobackup format configured to disk using


CONFIGURE CONTROLFILE AUTOBACKUP FORMAT
  FOR DEVICE TYPE DISK TO '?/oradata/cf_%F';


The format of the autobackup file for all configured devices is the substitution variable %F. This variable format translates into c-IIIIIIIIII-YYYYMMDD-QQ, where:

IIIIIIIIII stands for the DBID.

YYYYMMDD is a time stamp of the day the backup is generated

QQ is the hex sequence that starts with 00 and has a maximum of FFFor example, you can run the following command:

By default, the format of the autobackup file for all configured devices is the substitution variable %F. This variable format translates into c-IIIIIIIIII-YYYYMMDD-QQ, where:

IIIIIIIIII stands for the DBID.

YYYYMMDD is a time stamp of the day the backup is generated

QQ is the hex sequence that starts with 00 and has a maximum of FF

2.       Set the ORACLE_SID environment variable on Target Host to the same value used on Original/old/source host
[oracle@vm1 backup]$ export ORACLE_SID=trgt db_name>

3.       Start RMAN and connect to the target instance without connecting to the recovery catalog.
[oracle@vm1 backup]$ rman target / nocatalog

4.       Enter the following command to start the destination database with the nomount option:

RMAN> set dbid=<source database db_id value>;

RMAN> startup nomount;

RMAN will fail to find the server parameter file, which has not yet been restored, but will start the instance with a "dummy" file. Sample output follows:

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/inittrgt.ora'
starting Oracle instance without parameter file for retrieval of spfile

Total System Global Area     158662656 bytes

Fixed Size                     2226456 bytes
Variable Size                104859368 bytes
Database Buffers              46137344 bytes
Redo Buffers                   5439488 bytes

5.       Restore and edit the server parameter file.

Because you enabled the control file autobackup feature when making your backups, the server parameter file is included in the backup sets.

Allocate a channel to the media manager, then restore the server parameter file (SPFILE) as a client-side pararameter file (PFILE).

RMAN> run
{ allocate channel c1 device type sbt_tape PARMS='ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=trgt,OB2BARLIST=Hot-backup,OB2BARHOSTNAME=newhost)';
restore spfile to pfile '/u01/app/oracle/admin/trgt/pfile/inittrgt.ora' from autobackup;
shutdown abort;
                             }

6.       Next, edit the restored PFILE. Change any location-specific parameters, for example, those ending in _DEST and _PATH, to reflect the new directory structure. For example, edit the following parameters:

- IFILE
  - *_DUMP_DEST
  - LOG_ARCHIVE_DEST*
  - CONTROL_FILES

7.       Then restart the instance, using the edited PFILE:

startup force nomount ='/u01/app/oracle/admin/trgt/pfile/inittrgt.ora';

8.       Restore the control file from an autobackup and then mount the database. RMAN restores the control file to whatever location you specified in the CONTROL_FILES initialization parameter. For example:

RUN
{
  allocate channel c1 device type sbt_tape PARMS='ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=trgt,OB2BARLIST=Hot-backup,OB2BARHOSTNAME=newhost)'; 
restore controlfile from autobackup;
alter database mount;
}


9.       Query the database filenames recorded in the control file on the new host. Note, the controlfile was restored in step 8. 
sqlplus ‘ / as sysdba’

SQL > set lines 150
SQL > col name format a60
SQL> select file# ,name from v$datafile;
SQL> col member format a60
SQL >select group#,member from v$logfile;
SQL> exit


10.   Now, from the above output , we need create RMAN script to recover the database.
Ø  For each datafile, if we need to have different path in the new host, we need to user SET NEWNAME command to specify the different path in the host.  (If the file systems on the destination system are set up to have the same paths as the source host, then do not use SET NEWNAME for those files restored to the same path as on the source host.)
Ø  For each online redo log that is to be created at a different location than it had on the source host, use SQL ALTER DATABASE RENAME FILE commands to specify the pathname on the destination host. (If the file systems on the destination system are set up to have the same paths as the source host, then do not use ALTER DATABASE RENAME FILE for those files restored to the same path as on the source host.)
Ø  Perform a SET UNTIL to limit media recovery to the end of the archived redo logs.
Ø  Run SWITCH so that the control file recognizes the new path names as the official new names of the datafiles
Ø  Restore and recover the database


[oracle@vm1 ~]$ export ORACLE_SID=trgt
[oracle@vm1 ~]$ rman target / nocatalog

Recovery Manager: Release 11.2.0.3.0 - Production on Fri Jun 20 11:57:26 2014

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

The RMAN command to execute is as follows when we want to rename the datafiles and redo log file locations.

RUN
{
  # allocate a channel to the tape device
  ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS=''ENV=(OB2BARTYPE=Oracle8,OB2APPNAME=trgt,OB2BARLIST=Hot-backup,OB2BARHOSTNAME=newhost)'';

  # rename the datafiles and online redo logs
  SET NEWNAME FOR DATAFILE 1 TO '/data1/trgt/datafile/system01.dbf';
  SET NEWNAME FOR DATAFILE 2 TO /data1/trgt/datafile/sysaux01.dbf';
  SET NEWNAME FOR DATAFILE 3 TO '/data1/trgt/datafile/undotbs01.dbf';
  SET NEWNAME FOR DATAFILE 4 TO '/data1/trgt/datafile/users01.dbf';
  SET NEWNAME FOR DATAFILE 5 TO '/data1/trgt/datafile/newtest01.dbf';
  SET NEWNAME FOR DATAFILE 6 TO '/data1/trgt/datafile/blkcorrupt.dbf';
  SET NEWNAME FOR DATAFILE 7 TO '/data1/trgt/datafile/test_uncommit01.dbf';
  SET NEWNAME FOR DATAFILE 8 TO '/data1/trgt/datafile/users01.dbf';
  SQL "ALTER DATABASE RENAME FILE ''/data1/noasmdb/redofiles/redo_g01a.log''
      TO ''/data1/trgt/redofiles/redo01b.log'' ";
  SQL "ALTER DATABASE RENAME FILE ''/data1/noasmdb/redofiles/redo_g01b.log''
      TO ''/data1/trgt/redofiles/redo01b.log'' ";
  SQL "ALTER DATABASE RENAME FILE ''/data1/noasmdb/redofiles/redo_g02a.log''
      TO ''/data1/trgt/redofiles/redo02a.log'' ";
  SQL "ALTER DATABASE RENAME FILE ''/data1/noasmdb/redofiles/redo_g02b.log''
      TO ''/data1/trgt/redofiles/redo02b.log'' ";
  SQL "ALTER DATABASE RENAME FILE ''/data1/noasmdb/redofiles/redo_g03a.log''
      TO ''/data1/trgt/redofiles/redo03a.log'' ";
 SQL "ALTER DATABASE RENAME FILE ''/data1/noasmdb/redofiles/redo_g03b.log''
      TO ''/data1/trgt/redofiles/redo03b.log'' ";

  # restore the database and switch the datafile names
  RESTORE DATABASE;
  SWITCH DATAFILE ALL;
 
  # recover the database
  RECOVER DATABASE;
}


RMAN commands to restore & recover the database in the same path .

RMAN> restore database;

RMAN>recover database;


11.   Open the database with RESETLOGS options.

RMAN>alter database open resetlogs;


12.       Once the database is opened, take a fresh backup immediately.

No comments:

Post a Comment