RMAN Restarting DUPLICATE After A Failure

                Restarting DUPLICATE After a Failure
                       (Source: Oracle Docs)

RMAN automatically optimizes a DUPLICATE command that is a repeat of a previously failed DUPLICATE command.
The repeat DUPLICATE command notices which data files were successfully copied earlier and does not copy them again. 
This applies to all forms of duplication, whether they are backup-based (with or without a target connection) or active database duplication. The automatic optimization of the DUPLICATE command can be especially useful when a failure occurs during the duplication of very large databases.

To restart a duplicate operation:

    a. Exit RMAN.
    b. Start SQL*Plus and connect to the auxiliary instance with SYSDBA or SYSBACKUP privilege. 
    c. Start the auxiliary instance in NOMOUNT mode with the same SPFILE or PFILE specification that you used initially. 
    d. If you omitted this specification initially, then omit it again here.
       This example starts the auxiliary instance by using the parameters in the file /home/my_pfile.ora:

        STARTUP FORCE PFILE=/home/my_pfile.ora

    e. Exit SQL*Plus and start RMAN.
    f. Connect to the same databases as initially.
    g. Repeat the DUPLICATE command.

The second DUPLICATE operation:

    a. Locates the data files that were successfully duplicated by the initial DUPLICATE command.
    b. Displays a message similar to the following for each data file that it does not need to duplicate again:
    
      RMAN-05560: Using previous duplicated file /oradata/new/data01.f for datafile 1 with checkpoint SCN of 1654665

    c.Restores only the missing or incomplete data files, thereby avoiding recopying and restoring all the data files.

    d. If you do not want RMAN to automatically recover from a failed DUPLICATE operation, specify the keyword NORESUME to                disable the functionality. 
    e. Using the keyword NORESUME in the first invocation of DUPLICATE prevents a subsequent DUPLICATE command for the new                database from using this automatic optimization.

    This example assumes the following scenario:
    
    1. The source host and the destination host are different.
    2. Both the source database and the duplicate database manage database files by using ASM.
    3. The duplicate database files use a different directory structure than the source database.
    4. Network bandwidth on the source host is limited.
    5. The duplicate database must be opened after the duplication process completes.

    Use the following steps to create a duplicate database for the scenario that is described in this example:

    Plan the duplication:

    1. Choose a duplication technique that suits the scenario and requirements.
    2. Choose a strategy to name duplicate database files.
    3. In this example, the DB_CREATE_FILE_DEST initialization parameter is used to specify the location of the duplicate                database files.
    4. Configure six auxiliary channels on the auxiliary instance. 

In this example
 
a. there are two target channels configured on the source database. For RMAN to use backup sets to perform active database         duplication, the number of auxiliary channels must be equal to or greater than the number of target channels.
b. Ensure that the prerequisites for the chosen duplication technique are met.
c. Prepare the auxiliary instance.
d. Create the disk groups that will store the database files on the destination host.
e. If it does not already exist, create the +DGROUP2 disk group to store the duplicate database files.
f. Copy the password file from the source database to the destination database.
g. Set up Oracle net services connectivity between the source database and the auxiliary instance by using a static listener.
h. Copy the source database software keystore to the destination host. 
i. Specify the password that must be used to open the password-based software keystore by using the SET command.
j. Start the auxiliary instance in NOMOUNT mode.

sqlplus
startup nomount pfile=+DGROUP2//initdup.ora

k. Start RMAN and connect to the source database as TARGET and to the auxiliary instance as AUXILIARY.

rman
CONNECT TARGET sys@srcdb as SYSDBA;
CONNECT AUXILIARY sys@dupdb AS SYSBACKUP;

Duplicate the database by using the DUPLICATE command.

The SPFILE clause directs RMAN to copy the server parameter file from the source database to the auxiliary instance. Use the DB_CREATE_FILE_DEST parameter to specify the disk group that is used to store the duplicate database files in the duplicate database.

DUPLICATE DATABASE to dupdb
FROM ACTIVE DATABASE
PASSWORD FILE
SPFILE
SET DB_CREATE_FILE_DEST='+DGROUP2';

Example: 

Duplicating a Database to a Remote Host by Using Active Database Duplication with Image Copies
==============================================================================================
This example uses active database duplication with image copies to duplicate a database to a remote host.

This example assumes the following scenario:

a. The source host and the destination host are different.
b. The duplicate database files use a directory structure that is different from that of the source database.
c. The source database and the duplicate database use Oracle Managed Files (OMF) to create database files.
d. The source database must be available during the duplication process.
e. The duplicate database must be opened after the duplication process completes.
f. Use the following steps to create a duplicate database for the scenario that is described in this example:
g. Plan the duplication. This includes the following tasks:Choose a duplication technique that suits the scenario and       requirements.
h. Since the bandwidth between the source and destination is limited, active database duplication by using image copies is       performed.
i. Choose a strategy to name duplicate database files.

In this example, the 

DB_FILE_NAME_CONVERT and 
LOG_FILE_NAME_CONVERT 

initialization parameters are used to specify how the source database file names are converted to duplicate database file names.

if     you perform active database duplication by using image copies, 
then
    RMAN uses image copies  
    if     no auxiliary channels are configured 
        or 
        (the number of auxiliary channels <  the number of target channels)
    then
        no additional channels need to be configured to perform active database duplication by using image copies.
    end
end

Ensure that the prerequisites for the chosen duplication technique are met.
Prepare the auxiliary instance.
Create the directories that store the database files on the destination host.

In this example

01. create the

directory to store the data files, control file, and server parameter file and the        

directory to store the online redo log files.
02. On the destination host, create a minimal initialization parameter file for the auxiliary instance. The file is called         initdup.ora and is located in the directory. 

 

PFILE contains the following entries:

 

DB_NAME=dup
DB_DOMAIN = dup.example.com

 

1. Copy the password file from the source database to destination host.
2. Set up Oracle net services connectivity between the source database and the auxiliary instance by using a static listener.
3. Start the auxiliary instance in NOMOUNT mode.
4. Start RMAN and connect to the source database as TARGET and to the auxiliary instance as AUXILIARY.

 

(at OS command prompt)
rman
RMAN> CONNECT TARGET sys@srcdb as SYSDBA;
RMAN> CONNECT AUXILIARY sys@dupdb AS SYSBACKUP;

 

For active database duplication

 

1. connection to the auxiliary instance must also use password file authentication.
2. Duplicate the database by using the DUPLICATE command. 
3. Include the 
             a. SPFILE clause with the DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT parameters 
   to specify that the server parameter file from the source database must be used for the auxiliary instance.
4. The duplicate database files are stored in the duplicate database by using OMF-generated names. 
    The PARAMETER_VALUE_CONVERT option of the SPFILE clause specifies that the path name

should be        converted to .

 

DUPLICATE DATABASE TO dupdb
FROM ACTIVE DATABASE
PASSWORD FILE
SPFILE PARAMETER_VALUE_CONVERT='

',''
SET db_file_name_convert='',''
SET log_file_name_convert='','';

 

Example: 

 

Duplicating a Database to a Remote Host by Using Backup-based Duplication without a Target Connection or Recovery Catalog
=========================================================================================================================
This example describes how to perform duplication to a remote host by using backup-based duplication without a target connection or recovery catalog.

 

This example uses the following scenario:

 

01. A complete backup of the source database including the control files, data files, and archived redo log files is available      in the /backups/db_files directory on the destination host.
02. A connection to the target database or recovery catalog is not available.
03. The source host and destination host are different.
04. The duplicate database uses a directory structure that is different from that used by the source database to store the     duplicate database files. 
05. The data files and control file of the duplicate database files are stored in the /oracle2/database directory and the     online redo logs files are stored in /oracle2/database/logs directory.
06. The DB_NAME of the source database is "prod" and that of the duplicate database is "dup".
07. The duplicate database must be opened after the duplication process completes.

 

Use the following steps to create a duplicate database for the scenario that is described in this example:

 

01. Plan the duplication following the listed tasks:

 

    a. Choose a duplication technique that suits the scenario and requirements.
       In this example, backup-based duplication without a target connection or recovery catalog connection is                performed. Therefore, we use the BACKUP LOCATION clause to specify the location of the source database backups.
    b. Because the duplicate database uses a directory structure that is different from the source database, you must                choose a strategy to generate duplicate database file names.

 

In this example, the SET NEWNAME FOR DATABASE command specifies the location of the data files and control file. 
The LOGFILE clause of the DUPLICATE command specifies the location of the online redo log files.

 

Copy the required backups to the destination host by using the same directory structure used on the source database.

 

In this example, the backups of the data files and archived redo log files must be stored in /backups/db_files and the backups of the control files and server parameter file in /backups/cf on the destination host.

 

Ensure that the prerequisites for the chosen duplication technique are met.

 

Prepare the auxiliary instance.
-------------------------------

 

01. Create the directories that will store the duplicate database files on the destination host.
02. In this example, you create the /oracle2/database directory to store the 
    data files, 
    control file, and 
    server parameter file. 
03. Create the /oracle2/database/logs directory to store the online redo log files.
04. Create a minimal initialization parameter file for the auxiliary instance.
05. The file is called initdup.ora and is located in the /oracle2/database directory. 
06. In addition to any other specific settings, it must contain the following entries:

 

DB_NAME = dup
DB_DOMAIN = dupdb.example.com

 

07. Create a password file for the auxiliary instance by using the orapwd utility. A password file is required because the duplicate database is being created on a remote host.

 

08. Set up Oracle Net Services connectivity between the source database and the auxiliary instance by using a static listener.
    This is required because this example duplicates a database to a remote host.
09. Start the auxiliary instance in NOMOUNT mode.
10. Start RMAN and connect to the source database as TARGET and to the auxiliary instance as AUXILIARY. at the OS prompt type "rman" to get into rman console.

 

rman
RMAN> CONNECT TARGET /
RMAN> CONNECT AUXILIARY sys@dup AS SYSBACKUP;

 

01. Duplicate the database by using the DUPLICATE command.
02. Include the BACKUP LOCATION clause to specify the location of the source database backups. 
03. Enclose the SET NEWNAME FOR DATABASE and DUPLICATE command within a RUN block. 
04. The LOGFILE clause specifies the names and location of the online redo log files. below is the run block. 

 

run
{
set newname for database to '/oracle2/database/%b';
duplicate database 'db12' to 'dup'
logfile group 1 ('/oracle2/database/logs/r1.f','/ oracle2/database/logs/r2.f') size 108m reuse, 
        group 2 ('/ oracle2/database/logs/r3.f','/oracle2/database/logs/r4.f') size 108m reuse
backup location '/backups/db_files';
}

 

Example: 

 

Duplicating a Database to a Remote Host by Using Backup-Based Duplication with a Recovery Catalog
==================================================================================================

 

This example describes how to perform duplication to a remote host by using backup-based duplication with a recovery catalog.

 

This example assumes the following scenario:

 

01. A complete backup of the source database is available on the source host. 
02. The backups of the data files and archived redo log files are stored in /bkups/db_files. 
03. The backups of the control files and server parameter file are stored in /bkups/cf.
04. A connection to the source database is not available, but a connection to the recovery catalog is available.
05. The source host and destination host are different. 
06. The destination host used OMF and has the Oracle Database software installed.
07. The duplicate database stores database files in a different directory structure than the source database. 
08. The database files of the duplicate database must be stored in the /app/oracle2/dbs directory.
09. The DB_NAME of the source database is ora and its Net Service name is oradb. 
10. The DB_NAME of the duplicate database is dup and its Net Service name is dupdb.
11. The read-only tablespaces in the source database must be excluded from the duplicate database.
12. The duplicate database must not be opened after the duplication process completes.

 

Use the following steps to create a duplicate database for the scenario that is described in this example:

 

a. Plan the duplication. 

 

This includes the following tasks:
    1. Choose a duplication technique that suits the scenario and requirements.
    2. In this example, backup-based duplication using a recovery catalog connection is performed.
    3. Choose a strategy to generate duplicate database file names.
        a. Since the duplicate database uses OMF, use the DB_CREATE_FILE_DEST parameter in the auxiliary instance's                   initialization parameter file to specify the directory in which the duplicate database files are stored.
        b. Use the NOOPEN clause of the DUPLICATE command to specify that the duplicate database "must not be opened                using RESETLOGS" after the duplication completes.
        c. Copy the required backups to the destination host using the same directory structure used on the source                    database.
        d. In this example, the backups of the data files and archived redo log files must be stored in            /scratch/db_files and the backups of the control files and server parameter file 
           in /scratch/cf on the destination host.

 

b. Ensure that the prerequisites for the chosen duplication technique are met.
c. Prepare the auxiliary instance.
d. Create the directories that will store the duplicate database files on the destination host.    
    1. In this example, you create the /app/oracle2/dbs directory to store the data files, control file, online redo log               files, and server parameter file.
d. Create an initialization parameter file for the auxiliary instance. The file is called initdup.ora and is located in the       directory. In addition to any other specific settings, it must contain the following entries:

 

DB_NAME=dup
DB_DOMAIN=dupdb.example.com
DB_CREATE_FILE_DEST=

 


e. Create a password file for the auxiliary instance by using the orapwd utility. A password file is required because the    duplicate database is being created on a remote host.
f. Set up Oracle net services connectivity between the source database and the auxiliary instance using a static listener. This    is required because this example duplicates a database to a remote host.
g. Start the auxiliary instance in NOMOUNT mode.

 

sqlplus
startup nomount pfile=/dup.ora

 

h. Start RMAN and connect to the source database as TARGET and to the auxiliary instance as AUXILIARY.
rman
RMAN> CONNECT TARGET sys@oradb;
RMAN> CONNECT AUXILIARY sys@dupdb;
Enter the passwords when prompted.

 

h. Duplicate the database by using the DUPLICATE command.

 

i. Include the SKIP READONLY clause to exclude the read-only tablespaces from the duplicate database. 
   Because there is no connection to a target database, you must specify the name of the target database 
   that is being duplicated.

 

DUPLICATE DATABASE db12 TO dup
SKIP READONLY;

 

Example: 

 

Duplicating a Database to a Remote Host by Using Backup-based Duplication with a Target Connection
===================================================================================================

 

This example describes how to perform duplication to a remote host by using backup-based duplication with a target connection.

 

This example uses the following scenario:

 

01. A complete backup of the source database including the control file, data files, and archived redo log files is available.
02. A connection to the source database is available.
03. The source host and destination host are different.
04. The source database is configured to use transparent encryption with a password-based software keystore.
05. The duplicate database uses the same directory structure and file names as the source database to store database files.
06. On the source host, the data file, control files and server parameter file are stored in 
    /app/db_home1/database and the online redo log files are stored in /app/db_home1/logfiles.
07. The DB_NAME of the source database is src and its Net Service name is srcdb. The DB_NAME of the duplicate database is dup       and its Net Service name is dupdb.
08. On the source host, backups of the data files and archived redo log files are stored in /bkups/oradata/db_files. The         backups of the control files and server parameter file are stored in /bkups/oradata/cf.
09. The tablespaces HR and SH must be excluded from the duplicate database.
10. The remaining tablespaces in the source database are self-contained and do not have links to the hr and sh tablespaces.
11. The duplicate database must be opened after the duplication process completes.

 

Use the following steps to create a duplicate database for the scenario that is described in this example:

 

Plan the duplication using following tasks:

 

a. Choose a duplication technique that is suitable for your scenario.

 

In this example

 

01. backup-based duplication by using a target connection is performed.
02. Because the duplicate database uses the same directory structure as source database, you need not specify an alternative        file naming strategy.
03. However, use the NOFILENAMECHECK clause in the DUPLICATE command to prevent RMAN from checking if the data files and online     redo logs files of the source database use the same names as that on the duplicate database.

 

b. Configure three additional auxiliary channels. Using additional auxiliary channels enhances the performance of the duplication process

 

c. Copy the required backups to the destination host using the same directory structure used on the source database.

 

In this example, the backups of the data files and archived redo log files must be stored in the     /bkups/oradata/db_files directory and the backups of the control file and server parameter file in the     /bkups/oradata/cf directory on the destination host.

 

d. Ensure that the prerequisites for the chosen duplication technique are met.
e. Prepare the auxiliary instance. Create the directories that store the duplicate database files on the destination host.

 

In this example, the source database and the duplicate database use the same directory structure. Create the     /app/database directory to store the data files, control file, and server parameter file and the /app/logfiles     directory to store the online redo log files.

 

f. Create a minimal initialization parameter file for the auxiliary instance. The file is called initdup.ora and is located in     the /app/database directory. It contains the following entries:

 

DB_NAME=dup
DB_DOMAIN = dup.example.com

 

g. Create a password file for the auxiliary instance by copying the password file from the source database to the duplicate database.

 

h. Set up Oracle Net Services connectivity between the source database and the auxiliary instance by using a static listener.

 

i. Start the auxiliary instance in NOMOUNT mode

 

sqlplus
startup nomount pfile=/app/database/initdup.ora

 

j. Start RMAN and connect to the source database as TARGET and to the auxiliary instance as AUXILIARY. These connections are established from the destination host and the auxiliary connection uses operating system authentication.

 

rman
RMAN> CONNECT TARGET sys@dupdb AS SYSBACKUP;
RMAN> CONNECT AUXILIARY /

 

k. Duplicate the database by using the DUPLICATE command.

 

Include the SKIP TABLEPACE clause to specify the tablespaces that must be omitted during the duplication process. Use the SPFILE clause to specify that the server parameter file from the source database must be restored and copied to the duplicate database.

 

DUPLICATE DATABASE TO dup
SPFILE
SKIP TABLESPACE HR, SH
NOFILENAMECHECK;

 


Duplicating a Database to the Local Host by Using Active Database Duplication
=============================================================================

 

This example uses active database duplication to duplicate a database to the local host.

 

This example assumes the following scenario:

 

01. The source host and the destination host are the same.
02. Both the source database and the duplicate database manage database files by using Oracle Managed Files (OMF).
03. The duplicate database files use a different directory structure than the source database.
04. The source database is run in ARCHIVELOG mode and is available during the duplication process.
05. The service name of the source database dbsrc and that of the duplicate database is dbdup. The source database uses a server parameter file (spfile).

 

Use the following steps to create a duplicate database for the scenario that is described in this example:

 

Plan the duplication.

 

This includes the following tasks:

 

01. Choose a duplication technique that suits the scenario and requirements
02. Because network bandwidth on the source host is limited, active database duplication by using backup sets is performed.
03. Choose a strategy to name duplicate database files

 

In this example, the DB_CREATE_FILE_DEST initialization parameter is used to specify the location of the duplicate database files.

 

To ensure that the source database files are not overwritten, do not include the NOFILENAMECHECK clause in the DUPLICATE command.

 

04. Configure auxiliary channels on the auxiliary instance

 

In this example, there are three target channels configured on the source database. 
For RMAN to use backup sets to perform active database duplication. 
The number of auxiliary channels must be equal to or greater than the number of target channels.

 

05. Ensure that the prerequisites for the chosen duplication technique are met.
06. Prepare the auxiliary instance.
07. Create the directories that store the database files on the destination host

 

In this example, create the /app/db_home3/dbs directory to store the data files, control file, and server parameter file and the /app/db_home3/logfiles directory to store the online redo log files.

 

Copy the password file from the source database to the duplicate database.

 

Create an initialization parameter file for the auxiliary instance with the following minimum parameters: 

 

DB_NAME
CONTROL_FILES
DB_CREATE_FILE_DEST and 
LOG_CREATE_FILE_DEST

 

Set up Oracle net services connectivity between the source database and the auxiliary instance by using a static listener.
Start the auxiliary instance in NOMOUNT mode.

 

sqlplus
startup nomount pfile=//init.ora
Start RMAN and connect to the source database as TARGET and to the auxiliary instance as AUXILIARY. 
Both connections user net service names and hence NOT static listener name

 

rman
RMAN> CONNECT TARGET sys@srcdb as SYSDBA;   ---- source instance service name (as seen in listener.ora and tnsnames.ora) used 
RMAN> CONNECT AUXILIARY sys@dupdb AS SYSBACKUP; ----- auxiliary instance service name (as seen in listener.ora and tnsnames.ora) used

 

Note: For active database duplication, the connection to the auxiliary instance must also use password file authentication.
Duplicate the database by using the DUPLICATE command.

 

DUPLICATE DATABASE to dbdup
FROM ACTIVE DATABASE;

 


Duplicating PDBs to a New CDB by Using Active Database Duplication
==================================================================

 

This example describes how to use active database duplication to duplicate a PDB to a new CDB.

 

This example assumes the following scenario:

 

01.The source host and the destination host are different.
02. Both the source database and the duplicate database manage database files by using OMF.
03. Network bandwidth on the source host is limited.
04. The duplicate database files use a different directory structure than the source database.
05. Use the following steps to create a duplicate database for the scenario that is described in this example:
    Plan the duplication. This includes the following tasks:
        Choose a duplication technique that suits the scenario and requirements.
        Because network bandwidth on the source host is limited, 
        active database duplication by using backup sets is performed.
06.Choose a strategy to name duplicate database files.

 

In this example, the 

 

DB_FILE_NAME_CONVERT and 
LOG_FILE_NAME_CONVERT 

 

initialization parameters are used to specify the location of the duplicate database files.

 

07. Configure four auxiliary channels on the auxiliary instance.

 

    In this example, two (2) target channels are configured on the source database. 
    For RMAN to use backup sets to perform active database duplication
    The number of auxiliary channels must be equal to or greater than the number of target channels.

 

08. Ensure that the prerequisites for the chosen duplication technique are met.
09. Prepare the auxiliary instance.

 

Create the directories that store the database files on the destination host.
Create the /app/dbhome3/database directory to store the 
    data files, 
    control file, and 
    server parameter file and 
    /app/dbhome3/logfiles/online redo log files.

 

On the destination host, create a minimal initialization parameter file for the auxiliary instance. The file is called initdup.ora and contains the following entries:

 

ENABLE_PLUGGABLE_DATABASE=true
DB_NAME=dup
DB_DOMAIN = dup.example.com

 

10. Create the password file on the destination database by using the PASSWORD FILE option in the DUPLICATE command..
11. Set up Oracle net services connectivity between the source database and the auxiliary instance by using a "static listener".
12. Start the auxiliary instance in NOMOUNT mode. 

 

sqlplus
startup nomount pfile=//initdupdb.ora

 

13. Connect to the root as a common user with the SYSDBA or SYSBACKUP privilege.
14. Start RMAN and connect to the root of the source database as TARGET and to the auxiliary instance as AUXILIARY.

 

rman
RMAN> CONNECT TARGET sys@srcdb as SYSDBA;
RMAN> CONNECT AUXILIARY sys@dupdb AS SYSBACKUP;

 

Note: 

 

For active database duplication, connection to the auxiliary instance must also use password file authentication.
Ensure that the source CDB is open or mounted.
Duplicate the database by using the DUPLICATE command.

 

The SPFILE option directs RMAN to copy the server parameter file from the source database to the auxiliary instance. 
Use the DB_CREATE_FILE_DEST parameter to specify the disk group that is used to store the duplicate database files in the duplicate database.

 

DUPLICATE DATABASE to dupdb
PLUGGABLE DATABASE my_pdb
FROM ACTIVE DATABASE
PASSWORD FILE
SET DB_FILE_NAME_CONVERT='/app/dbhome/database','/app/dbhome3/database' 
SET LOG_FILE_NAME_CONVERT='/app/dbhome/logfiles','/app/dbhome3/logfiles';

 

Duplicating Databases

 

Example: 

 

Duplicating a PDB to an Existing CDB by Using Active Duplication
================================================================

 

This example describes how to use active database duplication to duplicate a PDB into an existing CDB.

 

The example assumes the following scenario:

 

01. The source CDB, cdb_src, and the destination CDB, cdb_dest, are on different hosts.
02. Both source and destination CDB use OMF to manage database files.
03. The source and destination CDBs have compatible set to 18.0.0 or higher.
04. The source CDB and the destination CDB use local undo.
05. The PDB being duplicated, my_pdb, is in read-write mode.
06. The source CDB and the destination CDB are open in read-write mode.
07. The initialization parameter REMOTE_RECOVERY_FILE_DEST which determines the location to which foreign archived redo log files are restored is set for the destination CDB.

 

a. Plan the duplication. This includes the following tasks:

 

    Because the PDB is being duplicated to an existing CDB, the only duplication technique available is active duplication.

 

b. Choose a strategy to name duplicate database files.

 

In this example, the DB_FILE_NAME_CONVERT initialization parameter is used to specify the location of the duplicate database files.

 

c. Configure four auxiliary channels on the destination CDB.

 

In this example:
There are three target channels configured on the source database. 
For RMAN to use backup sets to perform active database duplication, the number of auxiliary channels must be equal to or greater than the number of target channels.
Ensure that the prerequisites for active duplication and the additional prerequisites for duplicating a PDB to an existing CDB are met, as described in Oracle Database Backup and Recovery Reference.
Establish Oracle net connectivity between the source CDB and the destination CDB.
Create the directories that will store the duplicate database files on the destination host.
Start RMAN and connect as TARGET to the root of the source CDB and as AUXILIARY to the root of the destination CDB.

 

rman
RMAN> CONNECT TARGET sys@cdbsrc as SYSDBA;
RMAN> CONNECT AUXILIARY sys@cdbdup AS SYSBACKUP;

 

Note: 

 

For active database duplication, connection to the destination CDB must use password file authentication.
Duplicate the database by using the DUPLICATE command.
Use the DB_CREATE_FILE_DEST parameter to specify the disk group that is used to store the duplicate database files in the duplicate database.

 


DUPLICATE PLUGGABLE DATABASE my_pdb AS dup_pdb TO cdb_dest
FROM ACTIVE DATABASE
DB_FILE_NAME_CONVERT='/disk1/oracle/dbs','disk2/oracle/dbs';  

 

Delete the foreign archived redo log files that were restored to the location specified by the remote_recovery_file_dest initialization parameter as part of the duplication.

 

Example: 
Performing Backup-based Duplication by Using Encrypted Backups
RMAN enables you to use the DUPLICATE command to perform backup-based duplication by using encrypted backups.

 

This example uses the following scenario:

 

Assumption:

 

The source host and destination host are different.
---------------------------------------------------

 

Both source and destination database use OMF to manage database file names. 
However, the duplicate database uses a directory structure that is different from that of the source database.

 

Source database backups are encrypted by using transparent-mode encryption with the encryption key stored in a password-based software keystore. The keystore password is set up by using the following command (where password is a placeholder for the actual password that you enter):

 

ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY password;

 

A complete backup of the source database including the control files, data files, and archived redo log files is stored in the /oracle2/rman_backups directory.

 

The DB_NAME of source database is db_src and that of the duplicate database is dup_db.
The EXAMPLE and TOOLS tablespaces must be excluded from the duplicate database.
The duplicate database must be opened after the duplication process completes.
To perform backup-based database duplication by using encrypted backups:

 

Plan the duplication. 
--------------------

 

This includes the following tasks:

 

Choose a duplication technique that suits the scenario and requirements.
    In this example, backup-based duplication without target connection or recovery catalog connection is performed. 
    The BACKUP LOCATION option is used to specify the location of the source database backups.
Choose a strategy to generate duplicate database file names.

 

    Because the duplicate database uses a directory structure that is different from the source database, use the     DB_CREATE_FILE_DEST parameter in the auxiliary instance's initialization parameter file to specify the location in     which duplicate database files are stored.

 

    Copy the required backups to the destination host by using the same directory structure 
    that was used on the source database.
    Ensure that the prerequisites for the chosen duplication technique are met.

 

Prepare the auxiliary instance.

 

    Create the directories that store the database files on the destination host.
    In this example, create the /app/db_home2/database directory to store the data files, control file, and server     parameter file and the /app/db_home2/logfiles directory to store the online redo log files.

 

    Create a minimal initialization parameter file for the auxiliary instance.
    The file is called initdup.ora and is located in the /app/db_home2/database directory. It contains the following     entries:

 

    DB_NAME=dup_db
    DB_DOMAIN = dup.example.com
    DB_CREATE_FILE_DEST = /app/db_home2/database

 

    Copy the password file from the source database to destination host.A password file is required because the duplicate     database is being created on a remote host.

 

    Set up Oracle net services connectivity between the source database and the auxiliary instance by using a static     listener. This is required because this example duplicates a database to a remote host.

 

    Start the auxiliary instance in NOMOUNT mode by using the parameter file initdupdb.ora created in Step 3b.
    Start RMAN and connect to the source database as TARGET and to the auxiliary instance as AUXILIARY.
    rman
    RMAN> CONNECT TARGET /
    RMAN> CONNECT AUXILIARY sys@dup_db AS SYSBACKUP
    Enter the passwords when prompted.

 

    Because the source database backups used to duplicate the database are encrypted backups, specify the password that     must be used to open the software keystore that contains the encryption key (where password is a placeholder for the     actual password that you enter).

 

    SET DECRYPTION WALLET OPEN IDENTIFIED BY password;
    Note that the password specified in the SET command must the same as the one that was set on the source database by     using the 
    
    ALTER SYSTEM SET ENCRYPTION KEY command.

 

    Duplicate the database by using the DUPLICATE command.
    Before you perform the duplication, you must specify the password that must be used to decrypt the RMAN backups.

 

    DUPLICATE TARGET DATABASE TO 'dup_db'
    SKIP TABLESPACE example, tools
    PFILE '/ app/db_home2/initdupdb.ora'
    BACKUP LOCATION '/oracle2/rman_backups';

 


Example: 

 

Script to Duplicate a Database Using Backup-based Duplication
=============================================================

 

This example shows how to use a script to automate the process of duplicating a target database.

 

This example assumes the following:

 

    01. The backups of the target database are available to the auxiliary instance.
    02. The connection to the RMAN recovery catalog that contains metadata for the target database is available (connection         to the target database is not required).
    03. Both source and duplicate database use Oracle Managed Files (OMF).
    04. The operating system used is Linux or UNIX.
    05. The audit directory is created on the auxiliary database host.
    06. The prerequisites for backup-based duplication are met.
    
The script provided in this example performs the following tasks:
    a. Drops the auxiliary database.
    b. Backs up the target database.
    c. Creates a dummy auxiliary instance and opens it in NOMOUNT mode.
    d. Duplicates the target database by using the target database backups and metadata in the RMAN recovery catalog.
    e. The duplicate database control file is stored as +REDO/ORACLE_SID/CONTROLFILE/cf3.ctl and the data files are stored        in the +DATA directory.
    f. Verifies that the required objects are created in the duplicate database.
To duplicate a target database by using backup-based duplication without a target connection:

 

Create a parameter file (pfile) for the auxiliary instance. The pfile contains only the DB_NAME initialization        parameter, which is set to the SID of the duplicate database.

 

The following pfile, called init_dup.ora and located in the /home/oracle directory, sets the DB_NAME parameter. Replace     dup_db with the SID of your duplicate database:

 

*.db_name = 'dup_db'

 

Use a text editor and create a Shell script (called dup_db.sh in this example) with the contents shown below and with the following modifications:

 

Replace the value of the ORACLE_HOME variable with the Oracle home directory of your auxiliary instance.
Replace the value of the logdir variable with the directory in which you want to store log files.
Replace the following placeholders (shown in Italics) with values appropriate to your duplication scenario:

 

dup_db: SID and service name of the auxiliary instance
tgt_db: SID and service name of the target database
sys_pswd: Password for the SYS user of the target database
rman_cat_user: Name of the RMAN catalog user
cat_user_pswd: Password for the RMAN catalog user rman_cat_user
rman_catalog_db: SID of the RMAN catalog database
system_pswd: Password for the SYSTEM user in the target database

 

If     you want to store the duplicate database control file using a name and location that is different from 
    +REDO/ORACLE_SID/CONTROLFILE/cf3.ctl, 
then 
    replace the value of control_files in the dup_aux_db function with a value that is appropriate for your duplication     scenario.
end

 

If     you want to store the duplicate data files in a directory that is different from +DATA, 
then 
    replace the value of db_create_file_dest in the dup_aux_db function 
    with a value that is appropriate for your duplication scenario.

 


#!/bin/bash
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_2
export ORACLE_BASE=/uo1/app/oracle
export ORACLE_SID=dup_db
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:$ORACLE_HOME/Opatch
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib:/lib:/usr/lib;
export LD_LIBRARY_PATH
export logdir=/home/oracle/log
export dt='date +%y%m%d%H%M%S'
export NLS_DATE_FORMAT='DD-MM-YYYY HH24:MI:SS'

 

echo "drop auxiliary database."
function drop_aux_db {
export ORACLE_SID=dup_db
$ORACLE_HOME/bin/sqlplus -s '/ as sysdba' < set pagesize 999 linesize 999 heading off feedback off
select name, open_mode from v\$database;
shutdown immediate;
startup mount exclusive restrict;
drop database;
exit;
EOF2
}
echo "drop auxiliary database done."

 

echo "Backup the target database"
function backup_source_db {
$ORACLE_HOME/bin/rman target sys/sys_pswd@tgt_db catalog
rman_cat_user/cat_user_pswd@rman_catalog_db < RUN {
backup as backupset cumulative incremental level 1 database include current
controlfile plus archivelog not backed up delete input;}
exit;
EOF
}
echo "Backup the target database done."

 

sleep 120

 

echo "List the backup of the target database"
function check_source_db_backup {
$ORACLE_HOME/bin/rman target sys/sys_pswd@tgt_db catalog
rman_cat_user/cat_user_pswd@rman_catalog_db < LIST BACKUP OF DATABASE COMPLETED AFTER '(SYSDATE-1/24)';
EOF
}
echo "List the backup of the target database done."

 

echo "Start the auxiliary database in FORCE NOMOUNT mode"
function nomount_aux_db {
export ORACLE_SID=dup_db
$ORACLE_HOME/bin/rman target / < startup force nomount pfile='/home/oracle/init_dup.ora';
exit;
EOF2
}
echo "Start the auxiliary database in FORCE NOMOUNT mode done."

 

echo "Duplicate the target database"
function dup_aux_db {
export ORACLE_SID=dup_db
$ORACLE_HOME/bin/rman catalog rman_cat_user/cat_user_pswd@rman_catalog_db AUXILIARY /
< duplicate database tgt_db to dup_db spfile
set control_files '+REDO/${ORACLE_SID}/CONTROLFILE/cf3.ctl'
set db_create_file_dest '+DATA/' ;
exit;
EOF
}
echo "Duplicate the target database done"

 

echo "Check schema objects on the target"
function check_source_db {
$ORACLE_HOME/bin/sqlplus -s system/system_pswd@tgt_db < set pagesize 999 linesize 999 heading off feedback off
select name, open_mode from v\$database;
select table_name, num_rows from dba_tables where owner='SOE';
exit;
EOF2
}
echo "Check schema objects on the target done."

 

echo "Check schema objects on the auxiliary"
function check_aux_db {
export ORACLE_SID=dup_db
$ORACLE_HOME/bin/sqlplus -s '/ as sysdba' < set pagesize 999 linesize 999 heading off feedback off
select name, open_mode from v\$database;
select table_name, num_rows from dba_tables where owner='SOE';
exit;
EOF2
}
echo "Check schema objects on the auxiliary done"

 

drop_aux_db
backup_source_db
check_source_db_backup
nomount_aux_db
dup_aux_db
check_source_db
check_aux_db

 

Set execute permissions for the script dup_db.sh by using the chmod command.
$ chmod +x dup_db.sh

 

On the duplicate host (that hosts the duplicate database), run the dup_db.sh script.

 

The following command runs the dup_db.sh script that is stored in the /home/my_scripts/duplication directory:

 

$./home/my_scripts/duplication/dup_db.sh