Monday, April 6, 2009

RMAN Clone a Database

Clone a Database Using RMAN:
By means of the use of Recovery Manager it is possible to duplicate a database out from a previously taken rman backup.The method will be outlined in the next few lines.
Let's assume a source database named SRCDB and the target database, named GEMINI. A unix like environment is assumed, but it can be implemented on windows as well, just beware of the particular Oracle implementation on a windows platform (orapwd file name, service creation, path format)

1. Create a password file for the Cloned (GEMINI) instance:
orapwd file=/u01/app/oracle/product/9.2.0.1.0/dbs/orapwGEMINI password=password entries=10 2. Configure tnsnames.ora and listner.ora

Properly identify the database at the tnsnames.ora and have the instance manually registered against the listener.ora files, both files located at the $ORACLE_HOME/network/admin directory.

2.a Manually register the database against the listener (listener.ora)

(SID_DESC =
(ORACLE_HOME = /u01/app/oracle/product/9.2.0.1.0)
(SID_NAME = GEMINI)
)

2.b Added the target GEMINI to the tnsnames.ora

GEMINI =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = myhost.mydomain.com)(PORT = 1521)) )
(CONNECT_DATA =
(ORACLE_SID = GEMINI)
)
)

2.c Reload the listener
lsnrctl reload

3. Create a new init.ora for the cloned database.
Next create an init.ora file for the cloned database. In case the same paths cannot be used on the target host, either because it is the same source host or because those paths are not reproducible on the target, then DB_FILE_NAME_CONVERT and LOG_FILE_NAME_CONVERT may be required to be defined

DB_NAME=GEMINI
CONTROL_FILES=(/u02/oradata/GEMINI/control01.ctl,
/u02/oradata/GEMINI/control02.ctl,
/u02/oradata/GEMINI/control03.ctl)
# Convert file names to allow for different directory structure.
DB_FILE_NAME_CONVERT=(/u02/oradata/SRCDB/,/u02/oradata/GEMINI/)LOG_FILE_NAME_CONVERT=(/u01/oradata/SRCDB/,/u01/oradata/GEMINI/)
# block_size and compatible parameters must match those of the source database
DB_BLOCK_SIZE=8192
COMPATIBLE=9.2.0.0.0

4. Connect to the cloned instance
ORACLE_SID=GEMINI;
export ORACLE_SID
sqlplus /nologconn / as sysdba

5. Create an SPFILE based on the init.ora
CREATE SPFILE FROM PFILE='/u01/app/oracle/admin/GEMINI/pfile/init.ora';

6. Start the database in NOMOUNT mode:
STARTUP FORCE NOMOUNT;

7. Connect to the TARGET, CATALOG and AUXILIARY databases.
By means of the rman three connections are open, one for the Source Database (SOURCEDB), another for the Catalog database (RCAT), and one more for the cloned database (GEMINI)

ORACLE_SID=GEMINI; export ORACLE_SID
rman TARGET sys/password@SRCDB CATALOG rman/rman@RCAT AUXILIARY /

8. Complete or Incomplete clone (recover)
From the rman the database using one of the following commands:

8.a Clone the database by means of a complete recover.
DUPLICATE TARGET DATABASE TO GEMINI;

8.b Clone the database up to a defined point in time in the past by means of an incomplete
recover DUPLICATE TARGET DATABASE TO GEMINI UNTIL TIME 'SYSDATE-2';

9. Process finished.
Once the process is finished, the newly created GEMINI database is ready to be used as an independent new cloned database.

No comments:

Post a Comment