RMAN has the ability to duplicate, or clone, a database from a backup or from an active database. It is possible to create a duplicate database on a remote server with the same file structure, a remote server will a different file structure or the local server with a different file structure.
Target database : RMAN
Cloned database:RMANCL
Step 1:
Verifying the database name, Backups available in RMAN
SQL> select name,open_mode from v$database;
RMAN> SHOW CONTROLFILE AUTOBACKUP; RMAN> CROSSCHECK BACKUP OF DATABASE; RMAN> list backup of database; List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 1 Full 1.27G DISK 00:01:57 17-FEB-21 BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20210217T025333 Piece Name: /u01/app/oracle/fast_recovery_area/rman/RMAN/backupset/2021_02_17/o1_mf_nnndf_TAG20210217T025333_j2rfyph2_.bkp List of Datafiles in backup set 1 File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name ---- -- ---- ---------- --------- ----------- ------ ---- 1 Full 1460807 17-FEB-21 NO /u01/app/oracle/oradata/RMAN/datafile/o1_mf_system_j2ty19n0_.dbf 3 Full 1460807 17-FEB-21 NO /u01/app/oracle/oradata/RMAN/datafile/o1_mf_sysaux_j2rds2tn_.dbf 4 Full 1460807 17-FEB-21 NO /u01/app/oracle/oradata/RMAN/datafile/o1_mf_undotbs1_j2rdwp93_.dbf 7 Full 1460807 17-FEB-21 NO /u01/app/oracle/oradata/RMAN/datafile/o1_mf_users_j2rgo4bt_.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 3 Full 1.04M DISK 00:00:00 17-FEB-21 BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20210217T025714 Piece Name: /u01/app/oracle/fast_recovery_area/rman/RMAN/backupset/2021_02_17/o1_mf_nnndf_TAG20210217T025714_j2rg5l8o_.bkp List of Datafiles in backup set 3 File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name ---- -- ---- ---------- --------- ----------- ------ ---- 7 Full 1460921 17-FEB-21 NO /u01/app/oracle/oradata/RMAN/datafile/o1_mf_users_j2rgo4bt_.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 7 Full 1.20G DISK 00:00:51 18-FEB-21 BP Key: 7 Status: AVAILABLE Compressed: NO Tag: TAG20210218T012443 Piece Name: /u01/app/oracle/fast_recovery_area/rman/RMAN/backupset/2021_02_18/o1_mf_nnndf_TAG20210218T012443_j2tx43jg_.bkp List of Datafiles in backup set 7 File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name ---- -- ---- ---------- --------- ----------- ------ ---- 1 Full 1751323 18-FEB-21 NO /u01/app/oracle/oradata/RMAN/datafile/o1_mf_system_j2ty19n0_.dbf 3 Full 1751323 18-FEB-21 NO /u01/app/oracle/oradata/RMAN/datafile/o1_mf_sysaux_j2rds2tn_.dbf 4 Full 1751323 18-FEB-21 NO /u01/app/oracle/oradata/RMAN/datafile/o1_mf_undotbs1_j2rdwp93_.dbf 7 Full 1751323 18-FEB-21 NO /u01/app/oracle/oradata/RMAN/datafile/o1_mf_users_j2rgo4bt_.dbf Making a directory folder:
Step 2:
Creating Pfile for rmanclone:
[oracle@mercury dbs]$ vi initrmancl.ora
Step 3:
Copy target database password file to auxiliary database
cp orapwrman orapwrmancl
Step 4:
Copying the RMAN backup pieces and control file autobackup to desired location ‘RMANCL’
Step 5:
Verifying Listener and tns entries
[oracle@mercury dbs]$ rman target sys/oracle@rman
Recovery Manager: Release 12.2.0.1.0 – Production on Fri Feb 26 03:42:23 2021
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: RMAN (DBID=1951143712)
RMAN> connect auxiliary sys/oracle@rmancl connected to auxiliary database: RMANCL (not mounted)
[oracle@mercury admin]$ lsnrctl start
LSNRCTL for Linux: Version 12.2.0.1.0 – Production on 26-FEB-2021 03:41:09
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Starting /u01/app/oracle/product/12.2.0.1/db_1/bin/tnslsnr: please wait…
TNSLSNR for Linux: Version 12.2.0.1.0 – Production
System parameter file is /u01/app/oracle/product/12.2.0.1/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/mercury/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.27)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.27)(PORT=1521)))
STATUS of the LISTENER
————————
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 – Production
Start Date 26-FEB-2021 03:41:09
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/12.2.0.1/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/mercury/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.27)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary…
Service “RMAN” has 1 instance(s).
Instance “rman”, status UNKNOWN, has 1 handler(s) for this service…
Service “RMANCL” has 1 instance(s).
Instance “rmancl”, status UNKNOWN, has 1 handler(s) for this service…
The command completed successfully
[oracle@mercury admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /u01/app/oracle/product/12.2.0.1/db_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. rman = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.27)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = rman) ) ) rmancl = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.27)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = rmancl) ) )
Step 6:
Making the clone database in nomount state to duplicate the database
[oracle@mercury dbs]$ export ORACLE_SID=rmancl [oracle@mercury dbs]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Sat Feb 27 01:45:51 2021 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to an idle instance. SQL> startup nomount pfile=initrmancl.ora ORACLE instance started. Total System Global Area 243269632 bytes Fixed Size 8619256 bytes Variable Size 180357896 bytes Database Buffers 50331648 bytes Redo Buffers 3960832 bytes SQL> exit Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production [oracle@mercury dbs]$ rman auxiliary / Recovery Manager: Release 12.2.0.1.0 - Production on Sat Feb 27 01:48:32 2021 Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved. connected to auxiliary database: RMANCL (not mounted) RMAN> duplicate target database to rmancl backup location '/u01/app/oracle/flash_recovery_area' nofilenamecheck; Starting Duplicate Db at 27-FEB-21 contents of Memory Script: { sql clone "create spfile from memory"; } executing Memory Script sql statement: create spfile from memory contents of Memory Script: { shutdown clone immediate; startup clone nomount; } executing Memory Script Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 243269632 bytes Fixed Size 8619256 bytes Variable Size 180357896 bytes Database Buffers 50331648 bytes Redo Buffers 3960832 bytes contents of Memory Script: { sql clone "alter system set db_name = ''RMAN'' comment= ''Modified by RMAN duplicate'' scope=spfile"; sql clone "alter system set db_unique_name = ''rmancl'' comment= ''Modified by RMAN duplicate'' scope=spfile"; shutdown clone immediate; startup clone force nomount restore clone primary controlfile from '/u01/app/oracle/flash_recovery_area/o1_mf_s_1064798750_j2tx6720_.bkp'; alter clone database mount; } executing Memory Script sql statement: alter system set db_name = ''RMAN'' comment= ''Modified by RMAN duplicate'' scope=spfile sql statement: alter system set db_unique_name = ''rmancl'' comment= ''Modified by RMAN duplicate'' scope=spfile Oracle instance shut down Oracle instance started Total System Global Area 243269632 bytes Fixed Size 8619256 bytes Variable Size 180357896 bytes Database Buffers 50331648 bytes Redo Buffers 3960832 bytes Starting restore at 27-FEB-21 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=34 device type=DISK channel ORA_AUX_DISK_1: restoring control file channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03 output file name=/u01/app/oracle/oradata/rmancl/control01.ctl output file name=/u01/app/oracle/flash_recovery_area/rmancl/control02.ctl Finished restore at 27-FEB-21 database mounted released channel: ORA_AUX_DISK_1 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=34 device type=DISK contents of Memory Script: { set until scn 1751356; set newname for datafile 1 to "/u01/app/oracle/oradata/rmancl//o1_mf_system_j2rdccyh_.dbf"; set newname for datafile 3 to "/u01/app/oracle/oradata/rmancl//o1_mf_sysaux_j2rds2tn_.dbf"; set newname for datafile 4 to "/u01/app/oracle/oradata/rmancl//o1_mf_undotbs1_j2rdwp93_.dbf"; set newname for datafile 7 to "/u01/app/oracle/oradata/rmancl//o1_mf_users_j2rgo4bt_.dbf"; restore clone database ; } executing Memory Script executing command: SET until clause executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting restore at 27-FEB-21 using channel ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: starting datafile backup set restore channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/rmancl//o1_mf_system_j2rdccyh_.dbf channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/rmancl//o1_mf_sysaux_j2rds2tn_.dbf channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/rmancl//o1_mf_undotbs1_j2rdwp93_.dbf channel ORA_AUX_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/rmancl//o1_mf_users_j2rgo4bt_.dbf channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/o1_mf_nnndf_TAG20210218T012443_j2tx43jg_.bkp Message from syslogd@mercury at Feb 27 01:57:56 ... kernel:Stack: Message from syslogd@mercury at Feb 27 01:57:56 ... kernel:Call Trace: Message from syslogd@mercury at Feb 27 01:58:04 ... kernel:Code: 00 00 48 ff c9 48 8b 06 48 8b 5e 08 48 8b 56 10 4c 8b 46 18 4c 8b 4e 20 4c 8b 56 28 4c 8b 5e 30 4c 8b 66 38 0f 18 8e 40 01 00 00 channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/o1_mf_nnndf_TAG20210218T012443_j2tx43jg_.bkp tag=TAG20210218T012443 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:23:31 Finished restore at 27-FEB-21 contents of Memory Script: { switch clone datafile all; } executing Memory Script datafile 1 switched to datafile copy input datafile copy RECID=5 STAMP=1065579190 file name=/u01/app/oracle/oradata/rmancl/o1_mf_system_j2rdccyh_.dbf datafile 3 switched to datafile copy input datafile copy RECID=6 STAMP=1065579190 file name=/u01/app/oracle/oradata/rmancl/o1_mf_sysaux_j2rds2tn_.dbf datafile 4 switched to datafile copy input datafile copy RECID=7 STAMP=1065579190 file name=/u01/app/oracle/oradata/rmancl/o1_mf_undotbs1_j2rdwp93_.dbf datafile 7 switched to datafile copy input datafile copy RECID=8 STAMP=1065579190 file name=/u01/app/oracle/oradata/rmancl/o1_mf_users_j2rgo4bt_.dbf contents of Memory Script: { set until scn 1751356; recover clone database delete archivelog ; } executing Memory Script executing command: SET until clause Starting recover at 27-FEB-21 using channel ORA_AUX_DISK_1 starting media recovery channel ORA_AUX_DISK_1: starting archived log restore to default destination channel ORA_AUX_DISK_1: restoring archived log archived log thread=1 sequence=7 channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/flash_recovery_area/o1_mf_annnn_TAG20210218T012549_j2tx653s_.bkp channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/flash_recovery_area/o1_mf_annnn_TAG20210218T012549_j2tx653s_.bkp tag=TAG20210218T012549 channel ORA_AUX_DISK_1: restored backup piece 1 channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01 archived log file name=/u01/app/oracle/product/12.2.0.1/db_1/dbs/arch1_7_1064716579.dbf thread=1 sequence=7 channel clone_default: deleting archived log(s) archived log file name=/u01/app/oracle/product/12.2.0.1/db_1/dbs/arch1_7_1064716579.dbf RECID=1 STAMP=1065579191 media recovery complete, elapsed time: 00:00:00 Finished recover at 27-FEB-21 Oracle instance started Total System Global Area 243269632 bytes Fixed Size 8619256 bytes Variable Size 180357896 bytes Database Buffers 50331648 bytes Redo Buffers 3960832 bytes contents of Memory Script: { sql clone "alter system set db_name = ''RMANCL'' comment= ''Reset to original value by RMAN'' scope=spfile"; sql clone "alter system reset db_unique_name scope=spfile"; } executing Memory Script sql statement: alter system set db_name = ''RMANCL'' comment= ''Reset to original value by RMAN'' scope=spfile sql statement: alter system reset db_unique_name scope=spfile Oracle instance started Total System Global Area 243269632 bytes Fixed Size 8619256 bytes Variable Size 180357896 bytes Database Buffers 50331648 bytes Redo Buffers 3960832 bytes sql statement: CREATE CONTROLFILE REUSE SET DATABASE "RMANCL" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/u01/app/oracle/oradata/rmancl//o1_mf_1_j2rdyd0r_.log', '/u01/app/oracle/fast_recovery_area/rman/RMAN/onlinelog/o1_mf_1_j2rdyww7_.log' ) SIZE 200 M REUSE, GROUP 2 ( '/u01/app/oracle/oradata/rmancl//o1_mf_2_j2rdyd7h_.log', '/u01/app/oracle/fast_recovery_area/rman/RMAN/onlinelog/o1_mf_2_j2rdyxb9_.log' ) SIZE 200 M REUSE, GROUP 3 ( '/u01/app/oracle/oradata/rmancl//o1_mf_3_j2rdztwv_.log', '/u01/app/oracle/fast_recovery_area/rman/RMAN/onlinelog/o1_mf_3_j2rf05r5_.log' ) SIZE 200 M REUSE DATAFILE '/u01/app/oracle/oradata/rmancl/o1_mf_system_j2rdccyh_.dbf' CHARACTER SET AL32UTF8 contents of Memory Script: { set newname for tempfile 1 to "/u01/app/oracle/oradata/rmancl//o1_mf_temp_j2rf0z47_.tmp"; switch clone tempfile all; catalog clone datafilecopy "/u01/app/oracle/oradata/rmancl/o1_mf_sysaux_j2rds2tn_.dbf", "/u01/app/oracle/oradata/rmancl/o1_mf_undotbs1_j2rdwp93_.dbf", "/u01/app/oracle/oradata/rmancl/o1_mf_users_j2rgo4bt_.dbf"; switch clone datafile all; } executing Memory Script executing command: SET NEWNAME renamed tempfile 1 to /u01/app/oracle/oradata/rmancl//o1_mf_temp_j2rf0z47_.tmp in control file cataloged datafile copy datafile copy file name=/u01/app/oracle/oradata/rmancl/o1_mf_sysaux_j2rds2tn_.dbf RECID=1 STAMP=1065579217 cataloged datafile copy datafile copy file name=/u01/app/oracle/oradata/rmancl/o1_mf_undotbs1_j2rdwp93_.dbf RECID=2 STAMP=1065579217 cataloged datafile copy datafile copy file name=/u01/app/oracle/oradata/rmancl/o1_mf_users_j2rgo4bt_.dbf RECID=3 STAMP=1065579217 datafile 3 switched to datafile copy input datafile copy RECID=1 STAMP=1065579217 file name=/u01/app/oracle/oradata/rmancl/o1_mf_sysaux_j2rds2tn_.dbf datafile 4 switched to datafile copy input datafile copy RECID=2 STAMP=1065579217 file name=/u01/app/oracle/oradata/rmancl/o1_mf_undotbs1_j2rdwp93_.dbf datafile 7 switched to datafile copy input datafile copy RECID=3 STAMP=1065579217 file name=/u01/app/oracle/oradata/rmancl/o1_mf_users_j2rgo4bt_.dbf contents of Memory Script: { Alter clone database open resetlogs; } executing Memory Script database opened Cannot remove created server parameter file Finished Duplicate Db at 27-FEB-21 RMAN> exit Recovery Manager complete.
Step 7:
Now the database has been successfully cloned we can verify the database,