Examples: Duplicating Databases

  • Duplicating a Database to a Remote ASM Host Using Active Database Duplication with Backup Sets

This example assumes the following scenario:

The source host and the destination host are different.

Both the source database and the duplicate database manage database files using ASM.

The duplicate database files use a different directory structure than the source database.

Network bandwidth on the source host is limited.

The duplicate database must be opened after the duplication process completes.

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

  1. Plan the duplication as described in "Planning to Duplicate a Database". This includes the following tasks:
  1. Choose a duplication technique that suits the scenario and requirements.

Because network bandwidth on the source host is limited, we perform active database duplication using backup sets.

  1. 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.

  1. Configure six auxiliary channels on the auxiliary instance.

In this example, 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.

  1. Ensure that the prerequisites for the chosen duplication technique are met.
  2. Prepare the auxiliary instance as described in "Preparing the Auxiliary Instance".
  1. Create the disk groups that will store the database files on the destination host.

If it does not already exist, create the +DGROUP2 disk group to store the duplicate database files.

  1. Copy the password file from the source database to the destination database as described in "Creating a Password File for the Auxiliary Instance".
  2. Set up Oracle Net Services connectivity between the source database and the auxiliary instance using a static listener.
  3. Copy the source database software keystore to the destination host. Specify the password that must be used to open the password-based software keystore using the SET command.
  4. Start the auxiliary instance in NOMOUNT mode as described in "Starting the Auxiliary Instance".
  1. Start RMAN and connect to 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.

  1. Duplicate the database 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 Using Active Database Duplication with Image Copies

This example assumes the following scenario:

The source host and the destination host are different.

The duplicate database files use a directory structure that is different from that of the source database.

The source database and the duplicate database use Oracle Managed Files (OMF) to create database files.

The source database must be available during the duplication process.

The duplicate database must be opened after the duplication process completes.

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

  1. Plan the duplication as described in "Planning to Duplicate a Database". This includes the following tasks:
  1. Choose a duplication technique that suits the scenario and requirements.

Since the bandwidth between the source and destination is limited, we perform active database duplication using image copies.

  1. 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.

  1. When performing active database duplication using image copies, RMAN uses image copies either if no auxiliary channels are configured or if the number of auxiliary channels is lesser than the number of target channels. Therefore, no additional channels need to be configured to perform active database duplication using image copies.
  1. Ensure that the prerequisites for the chosen duplication technique are met.
  2. Prepare the auxiliary instance as described in "Preparing the Auxiliary Instance".
  1. Create the directories that will 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.

  1. 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 /app/db_home1/database directory. It contains the following entries:

DB_NAME=dup

DB_DOMAIN = dup.example.com

  1. Copy the password file from the source database to destination host as described in "Creating a Password File for the Auxiliary Instance"
  2. Set up Oracle Net Services connectivity between the source database and the auxiliary instance using a static listener as described in "Establishing Oracle Net Connectivity Between the Source Database and Auxiliary Instance".
  3. Start the auxiliary instance in NOMOUNT mode as described in "Starting the Auxiliary Instance".

  1. Start RMAN and connect to 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.

  1. Duplicate the database using the DUPLICATE command. Include the 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.

The duplicate database files are stored in the duplicate database using OMF-generated names. The PARAMETER_VALUE_CONVERT option of the SPFILE clause specifies that the path name /app/db_home1 should be converted to /app_db_home2.

DUPLICATE DATABASE TO dupdb

FROM ACTIVE DATABASE

PASSWORD FILE

SPFILE PARAMETER_VALUE_CONVERT='/app/dbhome1','/app/db_home2'

SET db_file_name_convert='/app/dbhome1/dbs','/app/db_home2/database/dbs'

SET log_file_name_convert='/app/dbhome1/log','/app/db_home2/logfiles';

Example: Duplicating a Database to a Remote Host by Using Backup-based Duplication without a Target Connection or Recovery Catalog

This example uses the following scenario:

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.

A connection to the target database or recovery catalog is not available.

The source host and destination host are different.

The duplicate database uses a directory structure that is different from that used by the source database to store the duplicate database files. 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.

The DB_NAME of the source database is db12 and that of the duplicate database is dup.

The duplicate database must be opened after the duplication process completes.

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

  1. Plan the duplication as described in "Planning to Duplicate a Database". This includes the following tasks:
  1. 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.

  1. 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.

  1. 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 /backups/db_files and the backups of the control files and server parameter file in /backups/cf on the destination host.

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

In this example, you create the /oracle2/database directory to store the data files, control file, and server parameter file. Create the /oracle2/database/logs directory to store the online redo log files.

  1. Create a minimal initialization parameter file for the auxiliary instance. The file is called initdup.ora and is located in the /oracle2/database directory. In addition to any other specific settings, it must contain the following entries:

DB_NAME = dup

DB_DOMAIN = dupdb.example.com

  1. 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.
  2. 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.
  3. Start the auxiliary instance in NOMOUNT mode as described in "Starting the Auxiliary Instance".
  1. 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 AS SYSBACKUP;

Enter the passwords when prompted.

  1. Duplicate the database by using the DUPLICATE command.

Include the BACKUP LOCATION clause to specify the location of the source database backups. Enclose the SET NEWNAME FOR DATABASE and DUPLICATE command within a RUN block. The LOGFILE clause specifies the names and location of the online redo log files.

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 4m reuse,

        group 2 ('/ oracle2/database/logs/r3.f','/oracle2/database/logs/r4.f') size 4m 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 assumes the following scenario:

A complete backup of the source database is available on the source host. The backups of the data files and archived redo log files are stored in /bkups/db_files. The backups of the control files and server parameter file are stored in /bkups/cf.

A connection to the source database is not available, but a connection to the recovery catalog is available.

The source host and destination host are different. The destination host used OMF and has the Oracle Database software installed.

The duplicate database stores database files in a different directory structure than the source database. The database files of the duplicate database must be stored in the /app/oracle2/dbs directory.

The DB_NAME of the source database is ora and its Net Service name is oradb. The DB_NAME of the duplicate database is dup and its Net Service name is dupdb.

The read-only tablespaces in the source database must be excluded from the duplicate database.

The duplicate database must not be opened after the duplication process completes.

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

  1. Plan the duplication as described in "Planning to Duplicate a Database". This includes the following tasks:
  1. Choose a duplication technique that suits the scenario and requirements.

In this example, backup-based duplication using a recovery catalog connection is performed.

  1. Choose a strategy to generate duplicate database file names.

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.

  1. Use the NOOPEN clause of the DUPLICATE command to specify that the duplicate database must not be opened using RESETLOGS after the duplication completes.
  2. 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 /scratch/db_files and the backups of the control files and server parameter file in /scratch/cf on the destination host.

  1. Ensure that the prerequisites for the chosen duplication technique are met.
  2. Prepare the auxiliary instance as described in "Preparing the Auxiliary Instance".
  1. Create the directories that will store the duplicate database files on the destination host.

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.

  1. Create an initialization parameter file for the auxiliary instance. The file is called initdup.ora and is located in the /app/oracle2/dbs 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= /app/oracle2/dbs

  1. 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.
  2. 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.
  3. Start the auxiliary instance in NOMOUNT mode as described in "Starting the Auxiliary Instance".
  1. 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.

  1. Duplicate the database by using the DUPLICATE command.

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 uses the following scenario:

A complete backup of the source database including the control file, data files, and archived redo log files is available.

A connection to the source database is available.

The source host and destination host are different.

The source database is configured to use transparent encryption with a password-based software keystore.

The duplicate database uses the same directory structure and file names as the source database to store database files.

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.

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.

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.

The tablespaces HR and SH must be excluded from the duplicate database

The remaining tablespaces in the source database are self-contained and do not have links to hr and sh.

The duplicate database must be opened after the duplication process completes.

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

  1. Plan the duplication as described in "Planning to Duplicate a Database". This includes the following tasks:
  1. Choose a duplication technique that is suitable for your scenario.

In this example, backup-based duplication using a target connection is performed.

  1. Because the duplicate database uses the same directory structure as source database, you need not specify an alternative file naming strategy.

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.

  1. Configure three additional auxiliary channels as described in "Configuring RMAN Channels for Use in Duplication". Using additional auxiliary channels enhances the performance of the duplication process
  2. 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 /bkups/oradata/db_files and the backups of the control file and server parameter file in /bkups/oradata/cf on the destination host.

  1. Ensure that the prerequisites for the chosen duplication technique are met.
  2. Prepare the auxiliary instance as described in "Preparing the Auxiliary Instance".
  1. Create the directories that will 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.

  1. 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

  1. Create a password file for the auxiliary instance by copying the password file from the source database to the duplicate database.
  2. Set up Oracle Net Services connectivity between the source database and the auxiliary instance using a static listener.
  3. Start the auxiliary instance in NOMOUNT mode as described in "Starting the Auxiliary Instance"
  1. 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 /

  1. 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;

Example: 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:

The source host and the destination host are the same.

Both the source database and the duplicate database manage database files by using Oracle Managed Files (OMF).

The duplicate database files use a different directory structure than the source database.

The source database is run in ARCHIVELOG mode and is available during the duplication process.

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:

  1. Plan the duplication, as described in "Planning to Duplicate a Database".

This includes the following tasks:

  1. 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.

  1. 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.

  1. 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.

  1. Ensure that the prerequisites for the chosen duplication technique are met, as described in "Prerequisites for Duplicating a Database".
  2. Prepare the auxiliary instance, as described in "Preparing the Auxiliary Instance".
  1. 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.

  1. Copy the password file from the source database to the duplicate database, as described in "Creating a Password File for the Auxiliary Instance".
  2. Create an initialization parameter file for the auxiliary instance with the following minimum parameters: DB_NAMECONTROL_FILESDB_CREATE_FILE_DEST, and LOG_CREATE_FILE_DEST.
  3. Set up Oracle net services connectivity between the source database and the auxiliary instance by using a static listener.
  4. Start the auxiliary instance in NOMOUNT mode, as described in "Starting the Auxiliary Instance".
  1. Start RMAN and connect to the source database as TARGET and to the auxiliary instance as AUXILIARY. Both connections user net service names.

%rman

RMAN> CONNECT TARGET sys@srcdb as SYSDBA;

RMAN> CONNECT AUXILIARY sys@dupdb AS SYSBACKUP;

Note: For active database duplication, the connection to the auxiliary instance must also use password file authentication.

  1. Duplicate the database by using the DUPLICATE command.

DUPLICATE DATABASE to dbdup FROM ACTIVE DATABASE;

Example: Performing Backup-based Duplication Using Encrypted Backups

RMAN enables you to use the DUPLICATE command to perform backup-based duplication using encrypted backups.

This example uses the following scenario:

  1. The source host and destination host are different.
  2. Both source and destination database use Oracle Managed Files (OMF) to manage database file names. However, the duplicate database uses a directory structure that is different from that of the source database.
  3. Source database backups are encrypted using transparent-mode encryption with the encryption key stored in a password-based software keystore. The keystore password is set up using a command such as the following (where password is a placeholder for the actual password that you enter):

ALTER SYSTEM SET ENCRYPTION KEY IDENTIFIED BY password;

  1. A complete backup of the source database including the control files, data files, and archived redo log files is stored in /oracle2/rman_backups.
  2. The DB_NAME of source database is db_src and that of the duplicate database is dup_db.
  3. The EXAMPLE and TOOLS tablespaces must be excluded from the duplicate database.
  4. The duplicate database must be opened after the duplication process completes.

To perform backup-based database duplication using encrypted backups:

  1. Plan the duplication as described in "Planning to Duplicate a Database". This includes the following tasks:
  1. 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 clause is used to specify the location of the source database backups.

  1. 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.

  1. Copy the required backups to the destination host using the same directory structure that was used on the source database.
  1. Ensure that the prerequisites for the chosen duplication technique are met.
  2. Prepare the auxiliary instance.
  1. Create the directories that will 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.

  1. 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.comDB_CREATE_FILE_DEST = /app/db_home2/database

  1. 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.
  2. 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.
  3. Start the auxiliary instance in NOMOUNT mode using the parameter file initdupdb.ora created in Step 3b.
  1. 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.

  1. 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 using the ALTER SYSTEM SET ENCRYPTION KEY command.

  1. Duplicate the database 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:

backups of the target database are available to the auxiliary instance

connection to the RMAN recovery catalog that contains metadata for the target database is available (connection to the target database is not required)

both source and duplicate database use Oracle Managed Files (OMF)

operating system used is Linux or UNIX

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 the auxiliary database

backs up the target database

creates a dummy auxiliary instance and opens it in NOMOUNT mode

duplicates the target database using the target database backups and metadata in the RMAN recovery catalog

The duplicate database control file is stored as +REDO/ORACLE_SID/CONTROLFILE/cf3.ctl and the data files are stored in the +DATA directory.

verifies that the required objects are created in the duplicate database

To duplicate a target database using backup-based duplication without a target connection:

  1. 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'

2. 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:

  1. Replace the value of the ORACLE_HOME variable with the Oracle home directory of your auxiliary instance.
  2. Replace the value of the logdir variable with the directory in which you want to store log files.
  3. 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 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

  1. 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.
  2. 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'

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 catalogrman_cat_user/cat_user_pswd@rman_catalog_db <<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 catalogrman_cat_user/cat_user_pswd@rman_catalog_db <<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 rman_cat_user/cat_user_pswd@rman_catalog_db 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

  1. Set execute permissions for the script dup_db.sh using the chmod command.

$ chmod +x dup_db.sh

  1. 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值