Database Duplication from Recovery Appliance
If you need to duplicate a protected database to create a standby database or to clone a protected database to a target host, you can do so by connecting to the Recovery Appliance catalog and using backup-based duplication. By using the catalog, there is no need to connect to the source database. Creating a standby database or a clone both involve running the RMAN DUPLICATE command.
Note:
DUPLICATE is the recommended method to create a clone database for standby database, development, or testing purposes, because a new DBID is created for the clone database.
If the protected database must be restored to a new host following the RMAN restore and recover to a new host procedure that keeps the same DBID, you must disconnect from the catalog before performing OPEN RESETLOGS or use SQL Plus to open the database.
See Also:
-
Oracle Database Backup and Recovery User’s Guide for additional information about duplicating databases
-
Oracle Database Backup and Recovery Reference for the syntax of the
DUPLICATEcommand
Creating a Standby Database for a Protected Database
When you create a standby database from Recovery Appliance, you connect to the standby (auxiliary instance) and to the Recovery Appliance catalog, and run the RMAN DUPLICATE command with the FOR STANDBY option.
Note: Because the primary database is already registered with the Recovery Appliance catalog, you should not register the standby database with the Recovery Appliance catalog.
To create a standby database for a protected database:
-
On the target host, prepare the auxiliary instance by performing the following tasks:
-
Create the directories in which the standby database files will be stored.
-
Create an initialization parameter file for the auxiliary instance.
The mandatory parameters are
DB_NAMEandDB_CREATE_FILE_DEST. -
Create a password file for the auxiliary database. This password file will be overwritten during the duplicate operation in step 3.
-
Establish Oracle Net connectivity between the protected database and the auxiliary instance.
-
Start the auxiliary instance in
NOMOUNTmode.
-
-
Start RMAN and connect as
CATALOGto the Recovery Appliance catalog and asAUXILIARYto the auxiliary instance.In the following example,
ra_rman_useris the Recovery Appliance user that the protected databasemy_ptdbuses to authenticate with the Recovery Appliance.ra1is the net service name of the target Recovery Appliance that is configured in the Oracle wallet.stdbyis the net service name of the auxiliary instance.%rman RMAN> CONNECT CATALOG ra_rman_user@ra1; RMAN> CONNECT AUXILIARY "sys@stdby AS SYSDBA"; -
Create the standby database using the
DUPLICATEcommand. Configure one or more auxiliary channels that correspond to the Recovery Appliance backup module.The following example configures three auxiliary channels and creates a standby database for the protected database
my_ptdb.RUN { ALLOCATE AUXILIARY CHANNEL c1 DEVICE TYPE sbt_tape PARMS='SBT_LIBRARY=/u01/oracle/product/12.1.0.2/dbhome_1/lib/libra.so, ENV=(RA_WALLET=location=file:/u01/oracle/product/12.1.0.2/dbhome_1/dbs/ra credential_alias=ra-scan:1521/zdlra5:dedicated)' FORMAT'%U_%d'; ALLOCATE AUXILIARY CHANNEL c2 DEVICE TYPE sbt_tape PARMS='SBT_LIBRARY=/u01/oracle/product/12.1.0.2/dbhome_1/lib/libra.so, ENV=(RA_WALLET=location=file:/u01/oracle/product/12.1.0.2/dbhome_1/dbs/ra credential_alias=ra-scan:1521/zdlra5:dedicated)' FORMAT'%U_%d'; ALLOCATE AUXILIARY CHANNEL c3 DEVICE TYPE sbt_tape PARMS='SBT_LIBRARY=/u01/oracle/product/12.1.0.2/dbhome_1/lib/libra.so, ENV=(RA_WALLET=location=file:/u01/oracle/product/12.1.0.2/dbhome_1/dbs/ra credential_alias=ra-scan:1521/zdlra5:dedicated)' FORMAT'%U_%d'; DUPLICATE DATABASE my_ptdb FOR STANDBY DORECOVER; }
Cloning a Protected Database
You can clone a protected database to a target host by using backup-based duplication. The Oracle-recommended method, covered in this section, connects to the Recovery Appliance catalog. By using a catalog for the duplicate operation, a connection to the source database is not required.
The example that follows represents the Oracle best practice for cloning a protected database and includes a sample script that you can customize for your scenario.
This example assumes the following:
-
backups of the target database exist on the Recovery Appliance and are available to the auxiliary instance
-
RMAN connection from the auxiliary database to the Recovery Appliance that contains metadata and backups for the target database is available
-
both source and duplicate database use Oracle Managed Files (OMF)
-
operating system used is Linux or UNIX
-
the audit directory is created on the auxiliary database host
-
prerequisites for backup-based duplication are met
The script provided in this example performs the following tasks:
-
drops an existing auxiliary database
-
backs up the target database
-
creates a dummy auxiliary instance and opens it in
NOMOUNTmode -
duplicates the target database using the target database backups and metadata available on the Recovery Appliance
The duplicate database control file is stored as
+REDO/ORACLE_SID/CONTROLFILE/cf3.ctland the data files are stored in the+DATAdirectory. -
verifies that the required objects are created in the duplicate database
To clone a protected database using backup-based duplication without a target connection:
-
Create a parameter file (pfile) for the auxiliary instance. The pfile contains only the
DB_NAMEinitialization parameter which is set to the SID of the duplicate database.The following pfile, called
init_dup.oraand located in the/home/oracledirectory, sets theDB_NAMEparameter. 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.shin this example) with the contents shown below and with the following modifications:-
Replace the value of the
ORACLE_HOMEvariable with the Oracle home directory of your auxiliary instance. -
Replace the value of the
logdirvariable 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: system identifier (SID) and service name of the auxiliary instance
tgt_db: SID and service name of the target database
sys_pswd: password for the
SYSuser of the target databasevpc_user: name of the VPC user
vpc_user_pswd: password for the VPC user vpc_user
ra_scan: Single Client Access Name (SCAN) of the Recovery Appliance
ra_servicename: service name of the Recovery Appliance metadata database
system_pswd: password for the
SYSTEMuser 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 ofcontrol_filesin thedup_aux_dbfunction with a value that is appropriate for your duplication scenario. -
If you want to store the duplicate data files in a directory that is different from
+DATA, then replace the value ofdb_create_file_destin thedup_aux_dbfunction 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' function drop_aux_db { export ORACLE_SID=dup_db $ORACLE_HOME/bin/sqlplus -s '/ as sysdba' <<EOF2 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 "Backup the target database" function backup_source_db { $ORACLE_HOME/bin/rman target sys/sys_pswd@tgt_db catalog vpc_user/vpc_user_pswd@ra_scan:1521/ra_serivcename:dedicated <<EOF RUN { backup as backupset cumulative incremental level 1 database include current controlfile plus archivelog not backed up delete input;} exit; EOF } 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 vpc_user/vpc_user_pswd@ra_scan:1521/ra_serivcename:dedicated <<EOF LIST BACKUP OF DATABASE COMPLETED AFTER '(SYSDATE-1/24)'; EOF } echo "Start the auxiliary database in FORCE NOMOUNT mode" function nomount_aux_db { export ORACLE_SID=dup_db $ORACLE_HOME/bin/rman target / <<EOF2 startup force nomount pfile='/home/oracle/init_dup.ora'; exit; EOF2 } echo "Duplicate the target database" function dup_aux_db { export ORACLE_SID=dup_db $ORACLE_HOME/bin/rman catalog vpc_user/vpc_user_pswd@ra_scan:1521/ra_serivcename:dedicated AUXILIARY / <<EOF 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 "Check schema objects on the target" function check_source_db { $ORACLE_HOME/bin/sqlplus -s system/system_pswd@tgt_db <<EOF2 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" function check_aux_db { export ORACLE_SID=dup_db $ORACLE_HOME/bin/sqlplus -s '/ as sysdba' <<EOF2 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 } 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 on the script
dup_db.shusing thechmodcommand.$ chmod +x dup_db.sh -
On the duplicate host (that hosts the duplicate database), run the
dup_db.shscript.The following command runs the
dup_db.shscript that is stored in the/home/my_scripts/duplicationdirectory:$ ./home/my_scripts/duplication/dup_db.sh