在相同的主机上创建一个duplicate数据库
source db:dbtest
auxiliary db:dupdb
duplicate database会自动分配一个新的DBID
要确保auxiliary channel能访问到所需的备份以及归档日志
1.备份source db
$ rman target /RMAN> backup database format ='/home/oracle/arch/dbbak_%U' plus archivelog;
2.修改监听文件,静态注册监听
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = testdb) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1/) (SID_NAME =testdb) ) (SID_DESC = (GLOBAL_DBNAME = dupdb) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1/) (SID_NAME =dupdb) ) )
3.修改tnsnames.ora文件
DBTEST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = testdb)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dbtest) ) ) DUPDB = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = testdb)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dupdb) ) )
4.为duplicate 数据库创建参数文件initdupdb.ora
db_name=dupdbdb_block_size=8192compatible=11.2.0.4.0remote_login_passwordfile=exclusivecontrol_files=('/u01/app/oracle/oradata/dupdb/control01.ctl','/u01/app/oracle/oradata/dupdb/control02.ctl')db_file_name_convert=('/u01/app/oracle/oradata/dbtest','/u01/app/oracle/oradata/dupdb')log_file_name_covert=('/u01/app/oracle/oradata/dbtest','/u01/app/oracle/oradata/dupdb')
#其他参数是可选的
5.启动auxiliary database(duplicate database)
$ export ORACLE_SID=dupdb$ sqlplus /nologSQL> connect /as sysdbaSQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initdupdb.ora'ORACLE instance started.Total System Global Area 317370368 bytesFixed Size 2252784 bytesVariable Size 260046864 bytesDatabase Buffers 50331648 bytesRedo Buffers 4739072 bytesSQL>
6.启动rman
$ export ORACLE_SID=dupdb$ rman Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jun 25 07:52:09 2015Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.RMAN> connect target sys/system1@dbtestconnected to target database: DBTEST (DBID=1275290034)RMAN> connect auxiliary /connected to auxiliary database: DUPDB (not mounted)RMAN>
7.启动duplicate database操作
RMAN> duplicate target database to dupdb;
以下为duplicate命令的执行结果:
RMAN> duplicate target database to dupdb;Starting Duplicate Db at 25-JUN-2015 08:18:24using target database control file instead of recovery catalogallocated channel: ORA_AUX_DISK_1channel ORA_AUX_DISK_1: SID=396 device type=DISKcontents of Memory Script:{ sql clone "create spfile from memory";}executing Memory Scriptsql statement: create spfile from memorycontents of Memory Script:{ shutdown clone immediate; startup clone nomount;}executing Memory ScriptOracle instance shut downconnected to auxiliary database (not started)Oracle instance startedTotal System Global Area 321548288 bytesFixed Size 2252824 bytesVariable Size 264245224 bytesDatabase Buffers 50331648 bytesRedo Buffers 4718592 bytescontents of Memory Script:{ sql clone "alter system set db_name = ''DBTEST'' comment= ''Modified by RMAN duplicate'' scope=spfile"; sql clone "alter system set db_unique_name = ''DUPDB'' comment= ''Modified by RMAN duplicate'' scope=spfile"; shutdown clone immediate; startup clone force nomount restore clone primary controlfile; alter clone database mount;}executing Memory Scriptsql statement: alter system set db_name = ''DBTEST'' comment= ''Modified by RMAN duplicate'' scope=spfilesql statement: alter system set db_unique_name = ''DUPDB'' comment= ''Modified by RMAN duplicate'' scope=spfileOracle instance shut downOracle instance startedTotal System Global Area 321548288 bytesFixed Size 2252824 bytesVariable Size 264245224 bytesDatabase Buffers 50331648 bytesRedo Buffers 4718592 bytesStarting restore at 25-JUN-2015 08:18:40allocated channel: ORA_AUX_DISK_1channel ORA_AUX_DISK_1: SID=396 device type=DISKchannel ORA_AUX_DISK_1: starting datafile backup set restorechannel ORA_AUX_DISK_1: restoring control filechannel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/DBTEST/autobackup/2015_06_25/o1_mf_s_883287663_brp8zhvt_.bkpchannel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/DBTEST/autobackup/2015_06_25/o1_mf_s_883287663_brp8zhvt_.bkp tag=TAG20150625T054103channel ORA_AUX_DISK_1: restored backup piece 1channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01output file name=/u01/app/oracle/oradata/dupdb/control01.ctloutput file name=/u01/app/oracle/oradata/dupdb/control02.ctlFinished restore at 25-JUN-2015 08:18:41database mountedcontents of Memory Script:{ set until scn 1553917; sql clone 'alter database flashback off'; set newname for datafile 1 to "/u01/app/oracle/oradata/dupdb/system01.dbf"; set newname for datafile 2 to "/u01/app/oracle/oradata/dupdb/sysaux01.dbf"; set newname for datafile 3 to "/u01/app/oracle/oradata/dupdb/undotbs01.dbf"; set newname for datafile 4 to "/u01/app/oracle/oradata/dupdb/users01.dbf"; set newname for datafile 5 to "/u01/app/oracle/oradata/dupdb/example01.dbf"; set newname for datafile 6 to "/u01/app/oracle/oradata/dupdb/nnc_data01.dbf"; set newname for datafile 7 to "/u01/app/oracle/oradata/dupdb/nnc_data02.dbf"; set newname for datafile 8 to "/u01/app/oracle/oradata/dupdb/nnc_data03.dbf"; set newname for datafile 9 to "/u01/app/oracle/oradata/dupdb/nnc_index01.dbf"; set newname for datafile 10 to "/u01/app/oracle/oradata/dupdb/nnc_index02.dbf"; set newname for datafile 11 to "/u01/app/oracle/oradata/dupdb/nnc_index03.dbf"; restore clone database ;}executing Memory Scriptexecuting command: SET until clausesql statement: alter database flashback offexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEStarting restore at 25-JUN-2015 08:18:46using channel ORA_AUX_DISK_1channel ORA_AUX_DISK_1: starting datafile backup set restorechannel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup setchannel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/dupdb/system01.dbfchannel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/dupdb/sysaux01.dbfchannel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/dupdb/undotbs01.dbfchannel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/dupdb/users01.dbfchannel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/dupdb/example01.dbfchannel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/dupdb/nnc_data01.dbfchannel ORA_AUX_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/dupdb/nnc_data02.dbfchannel ORA_AUX_DISK_1: restoring datafile 00008 to /u01/app/oracle/oradata/dupdb/nnc_data03.dbfchannel ORA_AUX_DISK_1: restoring datafile 00009 to /u01/app/oracle/oradata/dupdb/nnc_index01.dbfchannel ORA_AUX_DISK_1: restoring datafile 00010 to /u01/app/oracle/oradata/dupdb/nnc_index02.dbfchannel ORA_AUX_DISK_1: restoring datafile 00011 to /u01/app/oracle/oradata/dupdb/nnc_index03.dbfchannel ORA_AUX_DISK_1: reading from backup piece /home/oracle/arch/dbbak_0tqabpiv_1_1channel ORA_AUX_DISK_1: piece handle=/home/oracle/arch/dbbak_0tqabpiv_1_1 tag=TAG20150625T054047channel ORA_AUX_DISK_1: restored backup piece 1channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:25Finished restore at 25-JUN-2015 08:19:11contents of Memory Script:{ switch clone datafile all;}executing Memory Scriptdatafile 1 switched to datafile copyinput datafile copy RECID=13 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/system01.dbfdatafile 2 switched to datafile copyinput datafile copy RECID=14 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/sysaux01.dbfdatafile 3 switched to datafile copyinput datafile copy RECID=15 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/undotbs01.dbfdatafile 4 switched to datafile copyinput datafile copy RECID=16 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/users01.dbfdatafile 5 switched to datafile copyinput datafile copy RECID=17 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/example01.dbfdatafile 6 switched to datafile copyinput datafile copy RECID=18 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_data01.dbfdatafile 7 switched to datafile copyinput datafile copy RECID=19 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_data02.dbfdatafile 8 switched to datafile copyinput datafile copy RECID=20 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_data03.dbfdatafile 9 switched to datafile copyinput datafile copy RECID=21 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_index01.dbfdatafile 10 switched to datafile copyinput datafile copy RECID=22 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_index02.dbfdatafile 11 switched to datafile copyinput datafile copy RECID=23 STAMP=883297151 file name=/u01/app/oracle/oradata/dupdb/nnc_index03.dbfcontents of Memory Script:{ set until scn 1553917; recover clone database delete archivelog ;}executing Memory Scriptexecuting command: SET until clauseStarting recover at 25-JUN-2015 08:19:11using channel ORA_AUX_DISK_1starting media recoveryarchived log for thread 1 with sequence 10 is already on disk as file /home/oracle/arch/1_10_883118265.dbfarchived log for thread 1 with sequence 11 is already on disk as file /home/oracle/arch/1_11_883118265.dbfarchived log file name=/home/oracle/arch/1_10_883118265.dbf thread=1 sequence=10archived log file name=/home/oracle/arch/1_11_883118265.dbf thread=1 sequence=11media recovery complete, elapsed time: 00:00:01Finished recover at 25-JUN-2015 08:19:13Oracle instance startedTotal System Global Area 321548288 bytesFixed Size 2252824 bytesVariable Size 264245224 bytesDatabase Buffers 50331648 bytesRedo Buffers 4718592 bytescontents of Memory Script:{ sql clone "alter system set db_name = ''DUPDB'' comment= ''Reset to original value by RMAN'' scope=spfile"; sql clone "alter system reset db_unique_name scope=spfile"; shutdown clone immediate; startup clone nomount;}executing Memory Scriptsql statement: alter system set db_name = ''DUPDB'' comment= ''Reset to original value by RMAN'' scope=spfilesql statement: alter system reset db_unique_name scope=spfileOracle instance shut downconnected to auxiliary database (not started)Oracle instance startedTotal System Global Area 321548288 bytesFixed Size 2252824 bytesVariable Size 264245224 bytesDatabase Buffers 50331648 bytesRedo Buffers 4718592 bytessql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/u01/app/oracle/oradata/dupdb/redo01.log' ) SIZE 50 M REUSE, GROUP 2 ( '/u01/app/oracle/oradata/dupdb/redo02.log' ) SIZE 50 M REUSE, GROUP 3 ( '/u01/app/oracle/oradata/dupdb/redo03.log' ) SIZE 50 M REUSE DATAFILE '/u01/app/oracle/oradata/dupdb/system01.dbf' CHARACTER SET ZHS16GBKcontents of Memory Script:{ set newname for tempfile 1 to "/u01/app/oracle/oradata/dupdb/temp01.dbf"; switch clone tempfile all; catalog clone datafilecopy "/u01/app/oracle/oradata/dupdb/sysaux01.dbf", "/u01/app/oracle/oradata/dupdb/undotbs01.dbf", "/u01/app/oracle/oradata/dupdb/users01.dbf", "/u01/app/oracle/oradata/dupdb/example01.dbf", "/u01/app/oracle/oradata/dupdb/nnc_data01.dbf", "/u01/app/oracle/oradata/dupdb/nnc_data02.dbf", "/u01/app/oracle/oradata/dupdb/nnc_data03.dbf", "/u01/app/oracle/oradata/dupdb/nnc_index01.dbf", "/u01/app/oracle/oradata/dupdb/nnc_index02.dbf", "/u01/app/oracle/oradata/dupdb/nnc_index03.dbf"; switch clone datafile all;}executing Memory Scriptexecuting command: SET NEWNAMErenamed tempfile 1 to /u01/app/oracle/oradata/dupdb/temp01.dbf in control filecataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/dupdb/sysaux01.dbf RECID=1 STAMP=883297164cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/dupdb/undotbs01.dbf RECID=2 STAMP=883297164cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/dupdb/users01.dbf RECID=3 STAMP=883297164cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/dupdb/example01.dbf RECID=4 STAMP=883297164cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_data01.dbf RECID=5 STAMP=883297164cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_data02.dbf RECID=6 STAMP=883297164cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_data03.dbf RECID=7 STAMP=883297164cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_index01.dbf RECID=8 STAMP=883297164cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_index02.dbf RECID=9 STAMP=883297164cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/dupdb/nnc_index03.dbf RECID=10 STAMP=883297164datafile 2 switched to datafile copyinput datafile copy RECID=1 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/sysaux01.dbfdatafile 3 switched to datafile copyinput datafile copy RECID=2 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/undotbs01.dbfdatafile 4 switched to datafile copyinput datafile copy RECID=3 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/users01.dbfdatafile 5 switched to datafile copyinput datafile copy RECID=4 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/example01.dbfdatafile 6 switched to datafile copyinput datafile copy RECID=5 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_data01.dbfdatafile 7 switched to datafile copyinput datafile copy RECID=6 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_data02.dbfdatafile 8 switched to datafile copyinput datafile copy RECID=7 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_data03.dbfdatafile 9 switched to datafile copyinput datafile copy RECID=8 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_index01.dbfdatafile 10 switched to datafile copyinput datafile copy RECID=9 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_index02.dbfdatafile 11 switched to datafile copyinput datafile copy RECID=10 STAMP=883297164 file name=/u01/app/oracle/oradata/dupdb/nnc_index03.dbfcontents of Memory Script:{ Alter clone database open resetlogs;}executing Memory Scriptdatabase openedFinished Duplicate Db at 25-JUN-2015 08:19:28RMAN>