Duplicate DB using RMAN Backups - Step by Step

Step-by-step RMAN Duplicate Database !


How Recovery Manager Duplicates a Database
To prepare for database duplication, first create an auxiliary instance as described in "Preparing the RMAN DUPLICATE Auxiliary Instance: Basic Steps". For the duplication to work, you must connect RMAN to both the target (primary) database and an auxiliary instance started in NOMOUNT mode.
Allocate at least one auxiliary channel on the auxiliary instance. The principal work of the duplication is performed by the auxiliary channel, which starts a server session on the duplicate host. This channel then restores the necessary backups of the primary database, uses them to create the duplicate database, and initiates recovery.
So long as RMAN is able to connect to the primary and auxiliary instances, the RMAN client can run on any host. All backups and archived redo logs used for creating and recovering the duplicate database, however, must be accessible by the server session on the duplicate host. If the duplicate host is not the same as the target host, then you must make backups on disk on the target host available to the duplicate host with the same full path name as in the primary database
Use NFS or shared disks and make sure that the same path is accessible in the remote host. For example, the NFS mount point for both hosts could be /home/file_server.

As part of the duplicating operation, RMAN automates the following steps:
• Creates a control file for the duplicate database.
• Restores the target datafiles to the duplicate database and performs incomplete recovery by using all available incremental backups and archived redo logs.
• Shuts down and starts the auxiliary instance.
• Opens the duplicate database with the RESETLOGS option after incomplete recovery to create the online redo logs.
• Generates a new, unique DBID for the duplicate database.


RMAN DUPLICATE DATABASE: Options
When duplicating a database, you have the following options:
• You can run the DUPLICATE command with or without a recovery catalog.
• You can skip read-only tablespaces with the SKIP READONLY clause. Read-only tablespaces are included by default. If you omit them, then you can add them later.
• You can exclude tablespaces from the duplicate database with the SKIP TABLESPACE clause. You can exclude any tablespace except the SYSTEM tablespace or tablespaces containing rollback or undo segments.
• You can create the duplicate database in a new host. If the directory structure is the same on the new host, then you can specify the NOFILENAMECHECK option and reuse the target datafile filenames for the duplicate datafiles.
• By default, the DUPLICATE command creates the duplicate database from the most recent backups of the target database and then performs recovery to the most recent consistent point contained in the archived redo logs. 
• In some cases, you can set the duplicate database DB_NAME differently from the target database DB_NAME.

Renaming Database Files/Controlfiles/Redo logs/Temp files in RMAN Duplicate Database

• Renaming Control Files in RMAN DUPLICATE DATABASE
When choosing names for the duplicate control files, make sure you set the parameters in the initialization parameter file of the auxiliary database correctly; otherwise, you could overwrite the control files of the target database.
• Renaming Online Logs in RMAN DUPLICATE DATABASE
RMAN needs new names for the online redo log files of the duplicate database. Either you can specify the names explicitly in the DUPLICATE command, or you can let RMAN generate them according to the rules listed below:
Order Method Result
1 Specify the LOGFILE clause of DUPLICATE command. Creates online redo logs as specified.
2 Set LOG_FILE_NAME_CONVERT initialization parameter. Transforms target filenames, for example, from log_* to duplog_*. Note that you can specify multiple conversion pairs.

3 Set one of the Oracle Managed Files initialization parameters DB_CREATE_FILE_DEST, DB_CREATE_ONLINE_DEST_n, or DB_RECOVERY_FILE_DEST. Transforms target filenames based on the parameters set. The rules of precedence among these parameters are the same used by the SQL statement ALTER DATABASE ADD LOGFILE.
4 Do none of the preceding steps. Makes the duplicate filenames the same as the filenames from the target. You must specify the NOFILENAMECHECK option when using this method, and the duplicate database should be in a different host so that the online logs of the duplicate do not conflict with the originals.

• Renaming Datafiles in RMAN DUPLICATE DATABASE
There are several means of specifying new names to be used for the datafiles of your duplicate database. Listed in order of precedence, they are:
• Use the RMAN command SET NEWNAME FOR DATAFILE within a RUN block that encloses both the SET NEWNAME commands and the DUPLICATE command.
• Specify the DB_FILE_NAME_CONVERT parameter on the DUPLICATE command to specify a rule for converting filenames for any datafiles not renamed with SET NEWNAME or CONFIGURE AUXNAME.
Note:
The DB_FILE_NAME_CONVERT clause of the DUPLICATE command cannot be used to control generation of new names for files at the duplicate instance which are Oracle Managed Files (OMF) at the target instance. 

• Set the DB_CREATE_FILE_DEST initialization parameter to create Oracle Managed Files datafiles at the specified location.

If you do not use any of the preceding options, then the duplicate database reuses the original datafile locations from the target database.
It is possible for SET NEWNAME, or DB_FILE_NAME_CONVERT to generate a name that is already in use in the target database. In this case, specify NOFILENAMECHECK on the DUPLICATE command to avoid an error message.

Renaming Tempfiles in RMAN DUPLICATE DATABASE
RMAN re-creates datafiles for temporary tablespaces as part of the process of duplicating a database. There are several means of specifying locations for duplicate database tempfiles. Listed in order of precedence, they are:
• Use the SET NEWNAME FOR TEMPFILE command within a RUN block that encloses both the SET NEWNAME commands and the DUPLICATE command.

Preparing the RMAN DUPLICATE Auxiliary Instance: Basic Steps
To prepare the auxiliary instance used in RMAN DUPLICATE DATABASE, carry out the following tasks:
Task 1: Create an Oracle Password File for the Auxiliary Instance
orapwd file=orapwDUPDB password=oracle entries=5 force=yes
Task 2: Establish Oracle Net Connectivity to the Auxiliary Instance
The auxiliary instance must be accessible through Oracle Net. Before proceeding, start SQL*Plus to ensure that you can establish a connection to the auxiliary instance. Note that you must connect to the auxiliary instance with SYSDBA privileges, so a password file must exist.
Listener file:

# listener.ora Network Configuration File:
/u01/app/oracle/product/10.2.0/db_1/network/admin/listener.
ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = GGATE1)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (SID_NAME = GGATE1)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = DUPDB)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (SID_NAME = DUPDB)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.65)(PORT = 1521))
    )
  )


Tnsnames file:
PRODDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.140)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PRODDB)
    )
  )

DUPDB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.65)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = DUPDB)
    )
  )
EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
    )
  )

Task 3: Create an Initialization Parameter File for the Auxiliary Instance Create pfile from the source db and send it to Auxiliary location such as $ORACLE_HOME/dbs Make sure to change DB_NAME to reflect axiliary DB_NAME Change controlfile directory structure to reflect axiliary location and create directory at axiliary location. Change adump,bdump,cdump,udump directory structure to reflect axiliary directory and also create directory at axiliary location. Set other initialization parameters, including the parameters that allow you to connect as SYSDBA through Oracle Net, as needed. i.e *.remote_login_passwordfile='EXCLUSIVE' If you mention following parameter, then you don’t need to specify set newname when creating duplicate database. DB_FILE_NAME_CONVERT=(/u01/app/oracle/oradata/PROD/,/u01/app/oracle/oradata/DUPDB/) LOG_FILE_NAME_CONVERT=(/u01/app/oracle/oradata/PROD/redo, /u01/app/oracle/oradata/DUPDB/redo) After you create the client-side initialization parameter file, you can run the CREATE SPFILE command from SQL*Plus to create a server-side initialization parameter file at the Axiliary instance. SQL>CONNECT SYS/oracle@DUPDB AS SYSDBA SQL>startup NOMOUNT; SQL>CREATE SPFILE FROM PFILE='$ORACLE_HOME/dbs/initDUPDB.ora'; SQL>shutdown immediate; A server-side parameter file in the default location is an advantage when duplicating a database because you do not need to specify the PFILE parameter on the DUPLICATE command Task 4: Start the Auxiliary Instance Before beginning RMAN duplication, use SQL*Plus to connect to the auxiliary instance and start it in NOMOUNT mode (specifying a client-side parameter file if necessary). In this example, oracle is the password for the user with SYSDBA authority and DUPDB is the net service name for the auxiliary instance: Add a new entry to oratab, and source the environment Edit the /etc/oratab (or /opt/oracle/oratab) and add an entry for the new database. Source the new environment with '. oraenv' and verify that it has worked by issuing the following command: Echo $ORACLE_SID CONNECT SYS/oracle@DUPE AS SYSDBA -- start instance with the server parameter file SQL>STARTUP FORCE NOMOUNT; Because the auxiliary instance does not yet have a control file, you can only start the instance in NOMOUNT mode. Do not create a control file or try to mount or open the auxiliary instance. RMAN shuts down and restarts the auxiliary instance as part of the duplication. Hence, it is a good idea to create a server-side initialization parameter file for the auxiliary instance in the default location. If you do not have a server-side initialization parameter file for the auxiliary instance in the default location, then you must specify the client-side initialization parameter file with the PFILE parameter on the DUPLICATE command. The client-side parameter file for the auxiliary instance must reside on the same host as the RMAN client used to perform the duplication. Task 5: Mount or Open the Target Database Before beginning RMAN duplication, connect SQL*Plus to the target database and mount or open it if it is not already mounted or open. For example, enter: -- connect to target database SQL> CONNECT SYS/oracle@PROD AS SYSDBA; -- mount or open target database STARTUP MOUNT; Task 6: Make Sure You Have the Necessary Backups and Archived Redo Logs Make sure backups of all target datafiles and archived redo logs are accessible on the duplicate host. If you do not have backups of everything, then the duplicate operation fails. The database backup does not have to be a whole database backup: you can use a mix of full and incremental backups of individual datafiles. If you run rman from duplicate host, copy backup of datafile and archived log files to exactly same path to duplicate location i.e. if the backups are in /dsk1/bkp on the target host, then you might transfer them to /dsk1/bkp on the duplicate host. The new path—in this example, /dsk2/dup—must be accessible from both the target and duplicate hosts. Run the CATALOG command to add these copies to the RMAN repository at the duplicate host. Task 7: Allocate Auxiliary Channels if Automatic Channels Are Not Configured Start RMAN with a connection to the target database, the auxiliary instance, and, if applicable, the recovery catalog database. You can start the RMAN client on any host so long as it can connect to all the instances. In this example, a connection is established to three instances, all through the use of net service names: $ rman TARGET SYS/oracle@trgt CATALOG rman/cat@catdb AUXILIARY SYS/oracle@aux If you do not have automatic channels configured, then before issuing the DUPLICATE command, manually allocate at least one auxiliary channel within the same RUN command. The channel type (DISK or sbt) must match the media where the backups of the target database are located. If the backups reside on disk, then the more channels you allocate, the faster the duplication will be. For tape backups, limit the number of channels to the number of devices available. RUN { # SET NEWNAME If log_file_name_convert and \ db_file_name_convert is not already specified in init parameter SET NEWNAME FOR DATAFILE 1 TO '/u01/app/oracle/oradata/dupdb/system01.dbf'; # to manually allocate a channel of type sbt issue: ALLOCATE AUXILIARY CHANNEL ch1 DEVICE TYPE sbt; # to manually allocate three auxiliary channels for disk ALLOCATE AUXILIARY CHANNEL aux1 DEVICE TYPE DISK; ALLOCATE AUXILIARY CHANNEL aux2 DEVICE TYPE DISK; ALLOCATE AUXILIARY CHANNEL aux3 DEVICE TYPE DISK; DUPLICATE TARGET DATABASE TO DUPDB LOGFILE '/u01/app/oracle/oradata/ggate1/redo01.log' SIZE 50M, '/u01/app/oracle/oradata/ggate1/redo02.log' SIZE 50M, '/u01/app/oracle/oradata/ggate1/redo03.log' SIZE 50M; SKIP TABLESPACE tools; }
run {
SET NEWNAME FOR DATAFILE 1 TO '/u01/app/oracle/oradata/dupdb/system01.dbf';
SET NEWNAME FOR DATAFILE 2 TO '/u01/app/oracle/oradata/dupdb/undotbs01.dbf';
SET NEWNAME FOR DATAFILE 3 TO '/u01/app/oracle/oradata/dupdb/sysaux01.dbf';
SET NEWNAME FOR DATAFILE 4 TO '/u01/app/oracle/oradata/dupdb/users01.dbf';
SET NEWNAME FOR DATAFILE 5 TO '/u01/app/oracle/oradata/dupdb/example01.dbf';
SET NEWNAME FOR DATAFILE 6 TO '/u01/app/oracle/oradata/dupdb/testtbs.dbf';
SET NEWNAME FOR TEMPFILE 1 TO '/u01/app/oracle/oradata/dupdb/temp01.dbf';
ALLOCATE AUXILIARY CHANNEL aux1 DEVICE TYPE DISK;
ALLOCATE AUXILIARY CHANNEL aux2 DEVICE TYPE DISK;
ALLOCATE AUXILIARY CHANNEL aux3 DEVICE TYPE DISK;
DUPLICATE TARGET DATABASE TO DUPDB
LOGFILE
'/u01/app/oracle/oradata/dupdb/redo01.log' SIZE 50M,
'/u01/app/oracle/oradata/dupdb/redo02.log' SIZE 50M,
'/u01/app/oracle/oradata/dupdb/redo03.log' SIZE 50M;
}

No comments: