Can RMAN duplicate be used to “replace” an existing database

oracleoracle-11g-r2rman

I have an unused database B, not valuable. I'd like to make a copy of database A, but do not want to go through all the manual steps RMAN requires to set up the auxiliary database. Can I use RMAN duplicate to copy database B over database A, replacing everything in it but reusing the instance? I know you can synchronize database copies this way, I'm hoping this is just a more drastic version of that procedure.

Thanks!

Best Answer

The changes required to setup a duplicate from A (target) to B (auxiliary) in RMAN are pretty trivial.

1) db_file_name_convert AND log_file_name_convert parameters in the auxiliary database. If the file paths are exactly the same, simple name replacement should suffice:

db_file_name_convert='PROD','TEST'
log_file_name_convert='PROD','TEST'

IF your path changes are more complicated, you can specify full path replacement:

db_file_name_convert='/u01/oradata/PROD/system_PROD_01.dbf','/export/home/oracle/oradata/TEST/system_01.dbf','/u01/oradata/PROD/sysaux_PROD_01.dbf','/export/home/oracle/oradata/TEST/sysaux_01.dbf'
log_file_name_convert='/u02/oradata/PROD/redo_PROD_01.log','/export/home/oracle/oradata/TEST/redo_01.log','/u02/oradata/PROD/redo_PROD_02.log','/export/home/oracle/oradata/TEST/redo_02.log'

2) Make sure to setup an oracle password file for the instance and configured for remote login.

3) Make sure the target and auxiliary instances are configured in TNSNAMES.ORA on both instance servers (if they are different).

4) Shutdown B (auxiliary), remove all control files, redo logs and data files.

5) Startup B in NOMOUNT mode.

IF YOU ARE RUNNING 11G

6) Connect to rman like so:

rman target sys/change_on_install@A auxiliary sys/change_on_install@B

duplicate target database to "B" from active database;

Oracle will handle backup mode, compression, transport and unpack of the A database to replace the B database. When this completes, your database will be done.

IF YOU ARE RUNNING 10G

6) Configure flash recovery area in the target instance:

ALTER SYSTEM SET DB_RECOVERY_FILE_DEST_SIZE = 10G SCOPE=BOTH;
ALTER SYSTEM SET DB_RECOVERY_FILE_DEST = '/u01/oraflash' SCOPE=BOTH;

7) Backup database using rman. If your A (target) is in archive log mode, this can be done hot. If not, cold. Compressed below is optional. I always use it. The backupset ends up around 10-20% of the original instance size.

rman target sys/change_on_install@A

backup database as compressed backupset;

8) Using the location you chose above for the recovery area, copy the database to the server auxiliary is on (this is better if you have clustered/shared storage between the two servers). The date of course is the date you run the rman backup. Make sure the files end up in the same place. If there isn't room, you have options, but the easiest way on Unix/Linux is a symbolic link, or on Windows (NTFS only) a junction.

/u01/oraflash/PROD/backupset/2012_06_29

9) Using rman, duplicate the target database:

rman target sys/change_on_instance@A auxiliary sys/change_on_install@B

duplicate target database to "B";

AND, you are up.

IF you really want to do a new clone with "less" effort, then you can setup a very shell database (an init.ora file with only 1 parameter), and use the SPFILE parameter in the rman duplicate to copy the parameter file over to the new instance, converting every name based parameter on the way. The can be good, except when the test machine may have more than one instance, and memory tuning may need tweaking.