RMAN CLONING Using Recovery Catalog Rahmath Khan Patan The document has been prepared by taking into consideration the below mentioned details. Target DB Recovery Catalog Auxiliary DB Server I.P’s 192.168.0.11(PC:11) 192.168.0.9(PC:9) 192.168.0.10(PC:10) DB Name proddb rcdb auxdb Listener & TNS names proddb rcdb auxdb In this document, we have taken three servers as above Target DB = Database which is to be cloned Recovery Catalog = A database/repository of backup information of all the databases registered with RMAN Auxiliary DB = A cloned copy of the Target database. Note: Recovery Catalog DB can be either be created on a separate system (as in real time) or can be created in the target system itself. 2 Follow the below steps to clone a Production DB (proddb) to an Auxiliary DB (auxdb) using a Recovery Catalog DB (rcdb). Step-1: First create a Recovery Catalog DB on 192.168.0.9 server using DBCA with DB_name and SID as ‘rcdb’. Using Netca or manually editing the listener.ora file, configure a Listener by name ‘rcdb’ [oracle@PC:09 ~] $ cd $ORACLE_HOME/network/admin [oracle@PC:09 admin] $ vi listener.ora RCDB = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.9)(PORT = 1521)) ) ) ) SID_LIST_RCDB = (SID_LIST = (SID_DESC = (ORACLE_HOME =/u01/oracle/ora10g_home/) (SID_NAME =RCDB) ) ) Now, using Netca or manually editing the tnsnames.ora file, configure 3 TNS entries, each for 3 1.) Target DB 2.) Recovery Catalog 3.) Auxiliary DB with different port numbers. [oracle@PC:09 admin] $ vi tnsnames.ora RCDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.9)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME =RCDB) ) ) PRODDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.11)(PORT = 1522)) ) (CONNECT_DATA = (SERVICE_NAME =PRODDB) ) AUXDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.10)(PORT = 1523)) ) (CONNECT_DATA = (SERVICE_NAME =AUXDB) ) 4 Then, export the ORACLE_SID and login to sqlplus as sysdba [oracle@PC:09 ~]$ export ORACLE_SID=rcdb [oracle@PC:09 ~]$ sqlplus / as sysdba SQL> startup Check and confirm whether you are logged into the Recovery Catalog DB SQL> select instance_name from v$instance; SQL> select name from v$database; Now, create a user for recovery catalog , create and assign a default tablespace and temporary tablespace for that user. First …. let’s create a default tablespace, SQL> create tablespace rctbs datafile ‘/u01/oracle/oradata/rctbs01.dbf’ size 100m; SQL> create user rcuser identified by rc123 default tablespace rctbs temporary tablespace temp quota unlimited on rctbs; Grant the user with connect, resource and recovery catalog ownership privileges. SQL> grant connect, resource, recovery_catalog_owner to rcuser; SQL>exit Now, connect to RMAN using with the new user created above. [oracle@PC:09 ~] $ RMAN catalog rcuser/rc123 You will be seeing the RMAN prompt as soon as you hit enter after the above line. RMAN> 5 Create a catalog to store all the backup information of all the databases in it. RMAN> create catalog; Catalog created RMAN> exit STEP-2: Goto Target database server 192.168.0.11, (i.e proddb) and using Netca, configure a listener for the prodbd database. [oracle@PC:11 ~] $ cd $ORACLE_HOME/network/admin [oracle@PC:11 admin] $ vi listener.ora PRODDB = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.11)(PORT = 1522)) ) ) ) SID_LIST_PRODDB = (SID_LIST = (SID_DESC = (ORACLE_HOME =/u01/oracle/ora10g_home/) (SID_NAME = PRODDB) ) ) 6 Configure TNS entries for each of the databases given below 1.) Target DB 2.) Recovery Catalog 3.) Auxiliary Database [oracle@PC:11 admin] $ vi tnsnames.ora RCDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.9)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME =RCDB) ) ) PRODDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.11)(PORT = 1522)) ) (CONNECT_DATA = (SERVICE_NAME =PRODDB) ) AUXDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.10)(PORT = 1523)) ) (CONNECT_DATA = (SERVICE_NAME =AUXDB) ) 7 Now, create a directory in another mount point say ‘/u02’ for storing the backup of the Target Database taken through RMAN [oracle@PC:11 ~]$ cd /u02 [oracle@PC:10 /u02] $ mkdir rmanbkp Note: Create a similar directory on similar mount point in the Auxilary Database server because RMAN uses a centralized location to access the backups of the databases. STEP-3: Goto the Auxiliary DB server 192.168.0.10 (i.e auxdb), create a listener and 3 TNS entries each for the below mentioned databases same like you have created before. 1) Target DB 2) Recovery Catalog DB 3) Auxiliary DB You can use Oracle’s Netca to configure listener and TNS names for the databases but in this document, i have configured them by editing the listener.ora and tnsnames.ora files and making the entries manually. [oracle@PC:10 ~] $ cd $ORACLE_HOME/network/admin [oracle@PC:10 admin] $ vi listener.ora AUXDB = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.11)(PORT = 1523)) ) ) ) 8 SID_LIST_AUXDB = (SID_LIST = (SID_DESC = (ORACLE_HOME =/u01/oracle/ora10g_home/) (SID_NAME = AUXDB) ) ) ConfigureTNS Entries in tnsnames.ora file: [oracle@PC:10 admin]$ vi tnsnames.ora RCDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.9)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME =RCDB) ) ) PRODDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.11)(PORT = 1522)) ) (CONNECT_DATA = (SERVICE_NAME =PRODDB) ) AUXDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.10)(PORT = 1523)) ) 9 (CONNECT_DATA = (SERVICE_NAME =AUXDB) ) Note: To make it easy for you, just copy the entries in any one of the tnsnames.ora file and paste it into the tnsnames.ora file of other two databases. Then, you are done with configuring the TNS names. The purpose of configuring the LISTENER and TNSNAMES for each and every database is to access the all the three databases from any of the servers using the concept of Networking in ORACLE. Do TNSPING <SID> to all the 3 databases to check the connection is working fine or not STEP-4: -The next step is to register the Target database with the RMAN for storing the backup information of proddb in a central repository called Recovery Catalog. -As we have configured listeners and tnsnames for all the three databases, we can connect to RMAN from any of the three databases using RMAN commands. -In this document i have chosen to connect to RMAN from the Target DB server. -The below command connects to Target DB as SYS user and Recovery Catalog as ‘rcuser’ using a connecting string rcdb [oracle@PC:11 ~] $ RMAN target / catalog rcuser/rc123@rcdb RMAN> -This command registers the Target Database with RMAN and hence forth any backup taken on Target DB gets registered in the Recovery Catalog RMAN> register database; -Take backup of the Target database (proddb). RMAN> backup format=’/u02/rmanbkp/prodfull_%t.bkp’ database plus archivelog; 10 RMAN> exit Goto Auxiliary database server and create a directory ‘rmanbkp’ on ‘/u02’ mount point of the Auxiliary database. [oracle@PC:10 ~] $ cd /u02 [oracle@PC:10 u02] $ mkdir rmanbkp Now…go back to Target database’s RMAN backup storage location i.e /u02/rmanbkp and copy all the backup files to the directory created in previous step on Auxiliary Database. [oracle@PC:11 rmanbkp] $ scp *.bkp oracle@192.168.0.10:/u02/rmanbkp/ All the backup files are copied to the rman backup location on Auxiliary database. In the same way, goto $ORACLE_HOME/dbs location on Target database and copy and rename the pfile of proddb (i.e initproddb.ora) to the similar location on Auxiliary database. [PC:11 dbs]$ scp initproddb.ora oracle@192.168.0.10:/$ORACLE_HOME/dbs/initauxdb.ora STEP-5: After copying the pfile, goto the pfile location on Auxiliary database and edit it as below [oracle@PC:10 dbs]$ vi initauxdb.ora Edit and modify the following entries: 11 1.) Change all the occurrences of ‘prodb’ to ‘auxdb’ by using below command in vi editor :%s/proddb/auxdb/g 2.) Change the ORACLE_HOME, ORADATA(for datafiles) and dump locations in the pfile to the locations as per the locations in Auxiliary Database 3.) Add the below two lines at the end of the pfile *.db_file_name_convert=(‘/u01/oradata/proddb’, ‘/u01/oradata/auxdb) *.log_file_name_convert=(‘/u01/oradata/proddb’, ‘/u01/oradata/auxdb) The above commands are used to convert the filename of a new datafile on the Target database to a filename on the Auxiliary database Note: If you have multiplexed copies of redolog files, then make one more entry of ‘log_file_name_convert’ with the multiplexed location of Target Database and Auxiliary database. For Ex: log_file_name_convert=(‘/u02/oradata/proddb’, ‘/u02/oradata/auxdb’) 4.) Changes the archives location to the new archives location of the Auxiliary database. Now, create the directories in the Auxiliary database for datafiles, dump files and archives as specified in the pfile. [oracle@PC:10 ~]$ cd $ORACLE_HOME/admin [oracle@PC:10 admin]$ mkdir auxdb [oracle@PC:10 admin]$ cd auxdb ---- For dump folders [oracle@PC:10 auxdb]$ mkdir adump bdump cdump udump [oracle@PC:10 admin]$ cd /u01/oradata [oracle@PC:10 oradata]$ mkdir auxdb ---- For datafiles 12 [oracle@PC:10 oradata]$ cd /u02 [oracle@PC:10 u02]$ mkdir archives ----- For Archive log files As everything is in place now, we go ahead and login into sqlplus using SYS user and startup the ‘auxdb’ database in nomount phase and then connect to RMAN for duplicating the Target database to Auxiliary database using the RMAN backup stored in ‘/u02/rmanbkkp’ folder. Before that, [oracle@PC:10 ~]$ export ORACLE_SID=auxdb [oracle@PC:10 ~]$ sqlplus / as sysdba SQL> startpup nomount SQL> exit Exit from the sqlplus after the database is into nomount phase and then orapwd file for the Auxiliary database [oracle@PC:10 ~]$ cd $ORACLE_HOME/dbs [oracle@PC:10 dbs]$ orapwd file=orapwauxdb password=aux123 entries=5 [oracle@PC:10 ~]$ Note: Here if you try connecting to RMAN might end up with a error saying “rman: can’t open target” Don’t get annoyed with it…this is due to $PATH variable not been set properly. Just follow below steps and set the PATH variable for a smooth sailing into RMAN [oracle@PC:10 ~]$ echo $PATH What ever path displays on the screen, edit it and remove “/usr/X11R6/bin” and set the PATH [oracle@PC:10 ~]$ export <PATH - /usr/X11R6/bin> 13 Now, connect to RMAN using all the 3 database’s Users and Connecting Strings…so that you are connected to 1.) Target Database(proddb) 2.) Recovery Catalog (rcdb) and 3.) Auxiliary Database (auxdb – nomount phase) [oracle@PC:10 ~]$ RMAN target sys/oracle@proddb catalog rcuser/rc123@rcdb auxiliary sys/aux123@auxdb Recovery Manager: Release 10.2.0.1.0 - Production on Sat Apr 14 18:29:27 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. connected to target database: ORCL (DBID=1308049214) connected to recovery catalog database connected to auxiliary database: AUXDB (not mounted) RMAN> duplicate target database to auxdb; Once the duplication is Finished, exit from RMAN RMAN> exit After finish, the database is opened with RESETLOGS option by RMAN. Now, Login to sqlplus and check the instance name and database name [oracle@PC:10 ~]$ sqlplus / as sysdba SQL> select instance_name from v$instance; Instance Name -------------------AUXDB 14 SQL> select name from v$database; Name ______ AUXDB Finally, you have successfully cloned the proddb database on 192.168.0.11 server to the auxdb database on 192.168.0.10 server using RMAN backup and Recovery Catalog. ====================== {@} Congratulations {@} ========================== For Your Information: Once you execute the DUPLICATE database command, RMAN will collect the backup files from ‘/u02/rmanbkp’ location and start cloning the proddb database on to the auxdb database with the file locations and parameters set in the pfile. I’m posting here the complete transcript of the RMAN cloning execution displayed on the screen after executing the DUPLICATE database command [oracle@oracle dbs]$ rman target sys/oracle@orcl catalog rcuser/rc123@rcdb auxiliary sys/aux123 Recovery Manager: Release 10.2.0.1.0 - Production on Sat Apr 14 18:29:27 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. connected to target database: ORCL (DBID=1308049214) connected to recovery catalog database 15 connected to auxiliary database: AUXDB (not mounted) RMAN> duplicate target database to auxdb; Starting Duplicate Db at 14-APR-12 starting full resync of recovery catalog full resync complete using channel ORA_AUX_DISK_1 contents of Memory Script: { set until scn 590638; set newname for datafile 1 to "/u01/oracle/ora10g_home/product/oradata/auxdb/system01.dbf"; set newname for datafile 2 to "/u01/oracle/ora10g_home/product/oradata/auxdb/undotbs01.dbf"; set newname for datafile 3 to "/u01/oracle/ora10g_home/product/oradata/auxdb/sysaux01.dbf"; set newname for datafile 4 to "/u01/oracle/ora10g_home/product/oradata/auxdb/users01.dbf"; set newname for datafile 5 to "/u01/oracle/ora10g_home/product/oradata/auxdb/example01.dbf"; restore check readonly clone database ; } executing Memory Script 16 executing command: SET until clause executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting restore at 14-APR-12 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: starting datafile backupset restore channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set restoring datafile 00001 to /u01/oracle/ora10g_home/product/oradata/auxdb/system01.dbf restoring datafile 00002 to /u01/oracle/ora10g_home/product/oradata/auxdb/undotbs01.dbf restoring datafile 00003 to /u01/oracle/ora10g_home/product/oradata/auxdb/sysaux01.dbf restoring datafile 00004 to /u01/oracle/ora10g_home/product/oradata/auxdb/users01.dbf restoring datafile 00005 to /u01/oracle/ora10g_home/product/oradata/auxdb/example01.dbf channel ORA_AUX_DISK_1: reading from backup piece /u02/rmanbkp/orclfull_780603436.bkp channel ORA_AUX_DISK_1: restored backup piece 1 piece handle=/u02/rmanbkp/orclfull_780603436.bkp tag=TAG20120414T181716 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:26 Finished restore at 14-APR-12 sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AUXDB" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS MAXDATAFILES 100 MAXINSTANCES 8 3 17 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/u01/oracle/ora10g_home/product/oradata/auxdb/redo01.log' ) SIZE 50 M REUSE, GROUP 2 ( '/u01/oracle/ora10g_home/product/oradata/auxdb/redo02.log' ) SIZE 50 M REUSE, GROUP 3 ( '/u01/oracle/ora10g_home/product/oradata/auxdb/redo03.log' ) SIZE 50 M REUSE DATAFILE '/u01/oracle/ora10g_home/product/oradata/auxdb/system01.dbf' CHARACTER SET AL32UTF8 contents of Memory Script: { switch clone datafile all; } executing Memory Script released channel: ORA_AUX_DISK_1 datafile 2 switched to datafile copy input datafile copy recid=1 stamp=780604638 filename=/u01/oracle/ora10g_home/product/oradata/auxdb/undotbs01.dbf datafile 3 switched to datafile copy input datafile copy recid=2 stamp=780604638 filename=/u01/oracle/ora10g_home/product/oradata/auxdb/sysaux01.dbf datafile 4 switched to datafile copy input datafile copy recid=3 stamp=780604638 filename=/u01/oracle/ora10g_home/product/oradata/auxdb/users01.dbf datafile 5 switched to datafile copy input datafile copy recid=4 stamp=780604639 filename=/u01/oracle/ora10g_home/product/oradata/auxdb/example01.dbf 18 contents of Memory Script: { set until scn 590638; recover clone database delete archivelog ; } executing Memory Script executing command: SET until clause Starting recover at 14-APR-12 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: sid=159 devtype=DISK starting media recovery channel ORA_AUX_DISK_1: starting archive log restore to default destination channel ORA_AUX_DISK_1: restoring archive log archive log thread=1 sequence=15 channel ORA_AUX_DISK_1: reading from backup piece /u02/rmanbkp/orclfull_780603484.bkp channel ORA_AUX_DISK_1: restored backup piece 1 piece handle=/u02/rmanbkp/orclfull_780603484.bkp tag=TAG20120414T181804 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01 archive log filename=/u01/oracle/ora10g_home/product/flash_recovery_area/AUXDB/archivelog/2012_04_14/o1_mf_1_15 _7rlxnfv3_.arc thread=1 sequence=15 channel clone_default: deleting archive log(s) 19 archive log filename=/u01/oracle/ora10g_home/product/flash_recovery_area/AUXDB/archivelog/2012_04_14/o1_mf_1_15 _7rlxnfv3_.arc recid=1 stamp=780604645 media recovery complete, elapsed time: 00:00:04 Finished recover at 14-APR-12 contents of Memory Script: { shutdown clone; startup clone nomount ; } executing Memory Script database dismounted Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 285212672 bytes Fixed Size 1218992 bytes Variable Size 104859216 bytes Database Buffers 176160768 bytes Redo Buffers 2973696 bytes sql statement: CREATE CONTROLFILE REUSE SET DATABASE "AUXDB" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 20 LOGFILE GROUP 1 ( '/u01/oracle/ora10g_home/product/oradata/auxdb/redo01.log' ) SIZE 50 M REUSE, GROUP 2 ( '/u01/oracle/ora10g_home/product/oradata/auxdb/redo02.log' ) SIZE 50 M REUSE, GROUP 3 ( '/u01/oracle/ora10g_home/product/oradata/auxdb/redo03.log' ) SIZE 50 M REUSE DATAFILE '/u01/oracle/ora10g_home/product/oradata/auxdb/system01.dbf' CHARACTER SET AL32UTF8 contents of Memory Script: { set newname for tempfile 1 to "/u01/oracle/ora10g_home/product/oradata/auxdb/temp01.dbf"; switch clone tempfile all; catalog clone datafilecopy "/u01/oracle/ora10g_home/product/oradata/auxdb/undotbs01.dbf"; catalog clone datafilecopy "/u01/oracle/ora10g_home/product/oradata/auxdb/sysaux01.dbf"; catalog clone datafilecopy "/u01/oracle/ora10g_home/product/oradata/auxdb/users01.dbf"; catalog clone datafilecopy "/u01/oracle/ora10g_home/product/oradata/auxdb/example01.dbf"; switch clone datafile all; } executing Memory Script executing command: SET NEWNAME renamed temporary file 1 to /u01/oracle/ora10g_home/product/oradata/auxdb/temp01.dbf in control file cataloged datafile copy datafile copy filename=/u01/oracle/ora10g_home/product/oradata/auxdb/undotbs01.dbf recid=1 stamp=780604665 cataloged datafile copy 21 datafile copy filename=/u01/oracle/ora10g_home/product/oradata/auxdb/sysaux01.dbf recid=2 stamp=780604665 cataloged datafile copy datafile copy filename=/u01/oracle/ora10g_home/product/oradata/auxdb/users01.dbf recid=3 stamp=780604665 cataloged datafile copy datafile copy filename=/u01/oracle/ora10g_home/product/oradata/auxdb/example01.dbf recid=4 stamp=780604666 datafile 2 switched to datafile copy input datafile copy recid=1 stamp=780604665 filename=/u01/oracle/ora10g_home/product/oradata/auxdb/undotbs01.dbf datafile 3 switched to datafile copy input datafile copy recid=2 stamp=780604665 filename=/u01/oracle/ora10g_home/product/oradata/auxdb/sysaux01.dbf datafile 4 switched to datafile copy input datafile copy recid=3 stamp=780604665 filename=/u01/oracle/ora10g_home/product/oradata/auxdb/users01.dbf datafile 5 switched to datafile copy input datafile copy recid=4 stamp=780604666 filename=/u01/oracle/ora10g_home/product/oradata/auxdb/example01.dbf contents of Memory Script: { Alter clone database open resetlogs; } executing Memory Script database opened Finished Duplicate Db at 14-APR-12 22