You are on page 1of 4

How I duplicate a database using RMAN

This document aims to describe the duplication of a database using RMAN in a windows environment on Oracle 10g. It's quite easy to backup and recover a database using RMAN. But RMAN can do more than that. For instance, it is possible to duplicate a database from one server to another. I need this duplication ability because I got a database for training purpose. This database must be fresh to train my users with the latest customers information, products etc but also for the development team. However, its not possible to perform a cold backup because my system is critical. To help myself, I used this document: http://download.oracle.com/docs/cd/B14117_01/server.101/b10734/toc.htm The document above is really helpful but I've encountered some errors and had difficulties to connect to the remote server. I'm also facing this task with a more practical eye than the document. Before starting, a little convention: Values with [] are variables. It should be changed to fit others environment. Im going to call the live dbs host PRIMARY and the duplicated databases host AUXILIARY. Those are the terms used by RMAN. To make things simple, I like to use the same server architecture on both servers. This will avoid the renaming of files. Below is a list of things I will do: 1)On the PRIMARY host Add the option UR=A in the CONNECT_DATA part of my tnsnames.ora entry to connect to my auxiliary database. It should look like this:

AUXILIARY.WORLD = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (COMMUNITY = tcp.world)(PROTOCOL = TCP)(Host = AUXILIARY)(PORT = MYDBPORT)) ) (CONNECT_DATA = (SERVICE_NAME = AUXILIARY.WORLD)(UR=A)) ) Perform a backup with RMAN:

C:\>set oracle_sid= PRIMARYDB C:\>rman target / RMAN>backup database plus archivelog not backed up 1 times; Move the backup folder from PRIMARY to AUXILIARY host. I would move it to the same location as on the PRIMARY host.

2) On the AUXILIARY host RMAN does not recreate the folder structure as it is on production automatically, so it has to be done manually. They are: Datafiles folders Control files folders Traces folder Archives log folder pfile (I got a pfile folder where the SPFILE is located. Then in oracle_home\database I got a file called initSID.ora and inside this file the following line: SPFILE=[drive:\SPFILEpath\SPFILESID.ora]

The oracle service must be created on first hand. So, I copy the SPFILE from PRIMARY to AUXILIARY and move it in the same location as on the PRIMARY server. Then I create the service using oradim command: It is possible to create a new password for the sys user. The use of -syspwd option as in this example can do that. Otherwise, I would just copy the password file from PRIMARY. Its located in [ORACLE_HOME]\database] C:\>oradim -NEW -SID [as on PRIMARY] -syspwd acomplexepassword -startmode auto I would then create my listener using net services. I will also need to create my tnsnames.ora and sqlnet.ora for this new database. I find it more convenient to use implicit connection when logging in locally. To do so, I would add the following in my sqlnet.ora: SQLNET.AUTHENTICATION_SERVICES =(NTS,BEQ) With the BEQ option, it is possible if logging in on windows with a user belonging to ora_dba group, to connect locally without providing usernames and passwords. When this is done it is possible to connect to the database with SQLplus and start the database in nomount mode.

C:\set oracle_sid=SameAsPRIMARY C:\sqlplus / as sysdba (thats thanks to BEQ in sqlnet.ora) SQL>startup nomount If the database wont start with an error telling me its not finding the spfile, that means that the spfile is not located in [ORACLE_HOME]\database], or that it's not pointing to the right folder. In that case, it's still possible to start the database using the following command: SQL>startup nomount spfile=[alternate_path\SPFILESID.ora] 3) Go back to PRIMARY If everything has been prepared carefully, I will be able to connect to PRIMARY and AUXILIARY with RMAN from PRIMARY. C:\set oracle_sid=PRIMARY C:\rman target / auxiliary sys/acomplexepassword@tnsentry.world I'm connecting to PRIMARY without username and password but because I connect to AUXILIARY remotely, username and password is required. Then I run the following: RMAN>run{ RMAN>ALLOCATE AUXILIARY CHANNEL aux1 DEVICE TYPE DISK; RMAN>RMAN>ALLOCATE AUXILIARY CHANNEL aux2 DEVICE TYPE DISK; RMAN>ALLOCATE AUXILIARY CHANNEL aux3 DEVICE TYPE DISK; RMAN>DUPLICATE TARGET DATABASE TO SameAsPRIMARY NOFILENAMECHECK UNTIL TIME 'sysdate -0.04';} With this command I will allocate 3 auxiliary channels which will be used for the duplication. I use the same SID for AUXILIARY and for PRIMARY, so it's a bit scary and confusing (hence the SameAsPRIMARY naming). Its reassuring to know that the duplication wont work if the database is open. RMAN will just say that to run this command the database must be in nomount mode and return an error. Plus the command will connect only to auxiliary (specified at connection time) using the tnsnames value used in the connection to RMAN. Since RMAN is using the production repository to duplicate the database, it will try to recover the data with the latest archive logs created on production. But they have been moved manually and not existing in the AUXILIARY environment. If RMAN could move the archive logs continuously it would be a standby DB. So RMAN sends an error saying that its not finding some archive logs.

To solve this problem, I will run the duplicate command with the UNTIL TIME option. The best way Ive found is to specify UNTIL TIME sysdate - X. sysdate -1 is one day before. The duplication would be one day old. 1/24 = 0.04 would be one hour before current state of PRIMARY database. RMAN will automatically open the database when he's done recovering it. However, if for some reasons, archive logs were missing, the duplication process will stop. But this doesn't mean that the duplication has failed. Only the last step, opening the database did not happen. So, it's possible to open the database manually. At this point, because of the recovery, the database is already mounted. So we must run an alter database instead of a startup. On the AUXILIARY host, I run the following command: C:\>set oracle_sid= [sameasPRIMARY] C:\>sqlplus / as sysdba SQL> alter database open resetlogs; The database is duplicated.

Disclaimer: The information in this document is the opinion of the author, not of Oracle Corporation. Any content, materials, information or software downloaded or otherwise obtained through the use of the site is done at your own discretion and risk. Oracle shall have no responsibility for any damage to your computer system or loss of data that results form the download of any content, materials, information or software.

You might also like