Clone an 11gr2 DB from RMAN without connecting to the target database and recovery catalog

Rman 11g release 2 provides us the flexibility of creating the rman duplicate without connecting to the target database and recovery catalog.
All rman needs here is the location of the backup pieces (previously executed) which is accessible and rman reads the backup pieces and restores the spfile,controlfile,datafiles and archivelog files to perform the duplicate operation.

RMAN Options:
NOFILENAMECHECK
Prevents RMAN from checking whether the source database datafiles and online redo logs files share the same names as the duplicated files. This option is necessary when you are creating a duplicate database in a different host that has the same disk configuration, directory structure, and filenames as the host of the source database. If duplicating a database on the same host as the source database, then make sure that NOFILENAMECHECK is not set.
The NOFILENAMECHECK option is required when the standby and primary datafiles and online redo logs have identical filenames. Thus, if you want the duplicate database filenames to be the same as the source database filenames, and if the databases are in different hosts, then you must specify NOFILENAMECHECK

SPFILE ... SET 'string_pattern'
Sets the specified initialization parameters to the specified values. You can use SET to set the LOG_FILE_NAME_CONVERT parameter for the online redo logs.
It copies the server parameter file from the source database to the operating system-specific default location for this file on the standby database.
RMAN uses the server parameter file to start the auxiliary instance for standby database creation. Any remaining options of the DUPLICATE command are processed after the database instance is started with the server parameter file.
If you execute DUPLICATE with the SPFILE clause, then the auxiliary instance must already be started with a text-based initialization parameter file. In this case, the only required parameter in the temporary initialization parameter file is DB_NAME, which can be set to any arbitrary value. RMAN copies the binary server parameter file, modifies the parameters based on the settings in the SPFILE clause, and then restarts the standby instance with the server parameter file. When you specify SPFILE, RMAN never uses the temporary text-based initialization parameter file to start the instance.
If FROM ACTIVE DATABASE is specified on DUPLICATE, then a server parameter file must be in use by the source database instance. If FROM ACTIVE DATABASE is not specified on DUPLICATE, then RMAN restores a backup of the server parameter file to the standby database.


DORECOVER:
Specifies that RMAN should recover the standby database after creating it. If you specify an untilClause, then RMAN recovers to the specified SCN or time and leaves the database mounted.
RMAN leaves the standby database mounted after media recovery is complete, but does not place the standby database in manual or managed recovery mode. After RMAN creates the standby database, you must resolve any gap sequence before placing it in manual or managed recovery mode, or opening it in read-only mode.


PARAMETER_VALUE_CONVERT:
Replaces the first string with the second string in all matching initialization parameter values. Note that DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT are exceptions to this rule and are not affected.
You can use PARAMETER_VALUE_CONVERT to set a collection of initialization parameter values and avoid explicitly setting them all. For example, if the source database uses disk group +ALPHA while the standby database will use +BETA, then you could modify all parameters that refer to these disk groups by specifying SPFILE PARAMETER_VALUE_CONVERT (‘+ALHPA’,'+BETA’).



DB_FILE_NAME_CONVERT 'string_pattern'
Specifies a rule for creating the filenames for duplicate datafiles and tempfiles. Note that DB_FILE_NAME_CONVERT specified on the DUPLICATE command overrides the initialization parameter DB_FILE_NAME_CONVERT if it is set in the initialization parameter file.

Example:
DUPLICATE TARGET DATABASE TO dup1
  FROM ACTIVE DATABASE
  DB_FILE_NAME_CONVERT '/disk1','/disk2'
  SPFILE
    PARAMETER_VALUE_CONVERT '/disk1', '/disk2'
    SET LOG_FILE_NAME_CONVERT '/disk1','/disk2'
    SET SGA_MAX_SIZE '200M'
    SET SGA_TARGET '125M';

The PARAMETER_VALUE_CONVERT option substitutes /disk2 for /disk1 in all initialization parameters that specify filenames (with the exception of DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT). The SET LOG_FILE_NAME_CONVERT clause substitutes /disk2 for /disk1 in the filenames of the online redo logs of the duplicate database. The DB_FILE_NAME_CONVERT option replaces /disk1 with /disk2 in the names of the duplicate datafiles and tempfiles.


Another Example with Path Changes:
run {
    allocate channel prmy1 type disk;
    allocate channel prmy2 type disk;
    allocate auxiliary channel stby type disk;
    duplicate target database for standby from active database
    dorecover
    spfile
        parameter_value_convert 'FGUARD','STB_QAFGUARD'
        SET DB_UNIQUE_NAME='STB_QAFGUARD'
        set db_file_name_convert='/opt/oracle/oradata/FGUARD/','/opt/oracle/oradata/STB_QAFGUARD/'
        set log_file_name_convert='/opt/oracle/oradata/FGUARD/','/opt/oracle/oradata/STB_QAFGUARD/'
        set control_files='/u01/app/oracle/oradata/STB_QAFGUARD/control01.ctl','/u01/app/oracle/oradata/STB_QAFGUARD/control02.ctl'
        set log_archive_max_processes='5'
        set fal_client='STB_QAFGUARD'
        set fal_server='FGUARD'
        set standby_file_management='AUTO'
        set log_archive_config='dg_config=(FGUARD,STB_QAFGUARD)'
        set log_archive_dest_2='service=FGUARD ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=FGUARD'
     ;
     }


The steps involved in creating the duplicate database are as follows:

1) Take a backup of the database as follows:
RMAN > backup database plus archivelog;

or

RMAN> run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup as compressed backupset format '/oracle_backup/%d_%u' database plus archivelog
include current controlfile;
release channel c1;
release channel c2;
}


2) Make the backup pieces available for duplicate operation.
++ If the duplicate is going to happen on different server, move the backup pieces to a new server using commands like ftp,scp etc.
++ If the duplicate is going to happen on the same server as target, then you can either retain them in the same location where the backup was done or copy it to a required location.

3) Create a password file for the auxiliary instance.
For unix copy the password file from the target database to $ORACLE_HOME/dbs and rename it.
For windows copy the password file from the target database to %ORACLE_HOME/database and rename it.

4) Create a initialization parameter for the auxiliary instance with only one parameter DB_NAME.
echo DB_NAME='dup11r2' > initdup11r2.ora

5) Now start the auxiliary instance to no mount mode.

Unix Example
Just set the environment variables and start the instance.
% export ORACLE_SID=dup11r2
% export ORACLE_HOME=/home/oracle/ora11g
% export PATH=$ORACLE_HOME/bin:$PATH
% sqlplus "/as sysdba"
SQL > startup nomount


Windows Example
Create a service and then set the necessary environment variables and start the instance.

% oradim -new -sid dup11r2
set ORACLE_SID=dup11r2
set ORACLE_HOME=D:\Orahome\Ora11gr2
set PATH=D:\Orahome\Ora11gr2\bin;%PATH%
% sqlplus "/as sysdba"
SQL > startup nomount

6) Connect to the auxiliary instance from RMAN and perform the rman duplicate as follows:
% rman auxiliary /

RMAN > DUPLICATE DATABASE TO dup11r2
UNTIL TIME "TO_DATE('29-MAY-2010 14:16:42','DD-MON-YYYY HH24:MI:SS')"
SPFILE
set control_files='D:\dup11r2\c1.ctl'
set db_file_name_convert='D:\Database\Ora11g2\ora11g2','d:\dup11r2'
set log_file_name_convert='D:\Database\Ora11g2\ora11g2','d:\dup11r2'
BACKUP LOCATION 'D:\dup11r2'
;

Here use of the BACKUP LOCATION clause identifies the type of duplication as having no target connection, no recovery catalog and being backup-based.


Internally, RMAN will perform the following operations
- Rman restores the spfile from the backup pieces located in the mentioned location.

- Once the spfile is restored, rman sets appropriate values to the parameters mentioned the duplicate command. For example:
db_name
control_files
db_file_name_convert
log_file_name_convert
etc ...

- Once done, rman restarts the instance to no mount so that the changes can take effect.

- Rman now changes the value of the parameter db_name to the target database name to achieve the restore of the controlfile. The restored controlfile will have the db_name as of the target database name and since we cannot have a different db_name in the spfile and in the controlfile, rman will have to set the parameter db_name to the target database name and perform the restore of the datafiles and controlfiles.
Also here if the duplicate is happening on the same machine, then 2 controlfiles with the same db_name cannot be mounted. In order to achieve this the auxiliary instance will have the parameter db_unique_name set to a unique value. Rman takes care of this sets the db_uniqiue_name to the database name specified for the auxiliary database.

- After the above operation,controlfile is restored from the backup piece to the location provided for the parameter control_files.

- Now Rman restores the datafiles to the locations specified by the parameter log_file_name_convert.

- Recovery of the datafiles are performed.

- Once the recovery is completed, rman shuts down the database to reset the value of db_name to the value provided for the auxiliary database.

- Once this is done, the database is taken to no mount phase and the controlfile is recreated to change the database name and the id.This is followed by the database getting opened with resetlogs.