4.运行RMAN DUPLICATE命令
登录到A机:
$ rman target sys/oracle@A auxiliary sys/oracle@B
RMAN> duplicate target database to testdb from active database;
具体过程如下:
[oracle@JY-DB01 admin]$ rman target sys/oracle@A auxiliary sys/oracle@B Recovery Manager: Release 11.2.0.4.0 - Production on Thu Nov 5 15:44:57 2015 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORADB (DBID=2647366668) connected to auxiliary database: TESTDB (not mounted) RMAN> duplicate target database to testdb from active database; Starting Duplicate Db at 2015-11-05 15:46:44 using target database control file instead of recovery catalog allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=1 device type=DISK 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 238034944 bytes Fixed Size 2252016 bytes Variable Size 180355856 bytes Database Buffers 50331648 bytes Redo Buffers 5095424 bytes contents of Memory Script: { sql clone "alter system set control_files = ''/u01/oradata2/TESTDB/controlfile/o1_mf_c3p2gqj2_.ctl'' comment= ''Set by RMAN'' scope=spfile"; sql clone "alter system set db_name = ''ORADB'' comment= ''Modified by RMAN duplicate'' scope=spfile"; sql clone "alter system set db_unique_name = ''TESTDB'' comment= ''Modified by RMAN duplicate'' scope=spfile"; shutdown clone immediate; startup clone force nomount backup as copy current controlfile auxiliary format '/u01/oradata2/TESTDB/controlfile/o1_mf_c3p2gqjc_.ctl'; sql clone "alter system set control_files = ''/u01/oradata2/TESTDB/controlfile/o1_mf_c3p2gqjc_.ctl'' comment= ''Set by RMAN'' scope=spfile"; shutdown clone immediate; startup clone nomount; alter clone database mount; } executing Memory Script sql statement: alter system set control_files = ''/u01/oradata2/TESTDB/controlfile/o1_mf_c3p2gqj2_.ctl'' comment= ''Set by RMAN'' scope=spfile sql statement: alter system set db_name = ''ORADB'' comment= ''Modified by RMAN duplicate'' scope=spfile sql statement: alter system set db_unique_name = ''TESTDB'' comment= ''Modified by RMAN duplicate'' scope=spfile Oracle instance shut down Oracle instance started Total System Global Area 238034944 bytes Fixed Size 2252016 bytes Variable Size 180355856 bytes Database Buffers 50331648 bytes Redo Buffers 5095424 bytes Starting backup at 2015-11-05 15:47:29 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=46 device type=DISK channel ORA_DISK_1: starting datafile copy copying current control file output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_oradb.f tag=TAG20151105T154729 RECID=27 STAMP=894988050 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 2015-11-05 15:47:31 sql statement: alter system set control_files = ''/u01/oradata2/TESTDB/controlfile/o1_mf_c3p2gqjc_.ctl'' comment= ''Set by RMAN'' scope=spfile Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 238034944 bytes Fixed Size 2252016 bytes Variable Size 180355856 bytes Database Buffers 50331648 bytes Redo Buffers 5095424 bytes database mounted contents of Memory Script: { set newname for clone datafile 1 to new; set newname for clone datafile 2 to new; set newname for clone datafile 3 to new; set newname for clone datafile 4 to new; backup as copy reuse datafile 1 auxiliary format new datafile 2 auxiliary format new datafile 3 auxiliary format new datafile 4 auxiliary format new ; sql 'alter system archive log current'; } executing Memory Script executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME executing command: SET NEWNAME Starting backup at 2015-11-05 15:47:57 using channel ORA_DISK_1 channel ORA_DISK_1: starting datafile copy input datafile file number=00001 name=/u01/oradata/ORADB/datafile/o1_mf_system_c2v0xxm5_.dbf output file name=/u01/oradata2/TESTDB/datafile/o1_mf_system_4uqlgrpe_.dbf tag=TAG20151105T154757 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25 channel ORA_DISK_1: starting datafile copy input datafile file number=00002 name=/u01/oradata/ORADB/datafile/o1_mf_sysaux_c2v0xxp1_.dbf output file name=/u01/oradata2/TESTDB/datafile/o1_mf_sysaux_4vqlgrq7_.dbf tag=TAG20151105T154757 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile copy input datafile file number=00003 name=/u01/oradata/ORADB/datafile/o1_mf_undotbs1_c2v0xxpb_.dbf output file name=/u01/oradata2/TESTDB/datafile/o1_mf_undotbs1_50qlgrqm_.dbf tag=TAG20151105T154757 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03 channel ORA_DISK_1: starting datafile copy input datafile file number=00004 name=/u01/oradata/ORADB/datafile/users01.dbf output file name=/u01/oradata2/TESTDB/datafile/o1_mf_users_51qlgrqp_.dbf tag=TAG20151105T154757 channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01 Finished backup at 2015-11-05 15:48:43 sql statement: alter system archive log current contents of Memory Script: { backup as copy reuse archivelog like "/u01/oradb_arch1/1_146_894101903.dbf" auxiliary format "/opt/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_146_894101903.dbf" ; catalog clone archivelog "/opt/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_146_894101903.dbf"; switch clone datafile all; } executing Memory Script Starting backup at 2015-11-05 15:48:44 using channel ORA_DISK_1 channel ORA_DISK_1: starting archived log copy input archived log thread=1 sequence=146 RECID=252 STAMP=894988123 output file name=/opt/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_146_894101903.dbf RECID=0 STAMP=0 channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01 Finished backup at 2015-11-05 15:48:45 cataloged archived log archived log file name=/opt/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_146_894101903.dbf RECID=252 STAMP=894988217 datafile 1 switched to datafile copy input datafile copy RECID=27 STAMP=894988217 file name=/u01/oradata2/TESTDB/datafile/o1_mf_system_4uqlgrpe_.dbf datafile 2 switched to datafile copy input datafile copy RECID=28 STAMP=894988217 file name=/u01/oradata2/TESTDB/datafile/o1_mf_sysaux_4vqlgrq7_.dbf datafile 3 switched to datafile copy input datafile copy RECID=29 STAMP=894988217 file name=/u01/oradata2/TESTDB/datafile/o1_mf_undotbs1_50qlgrqm_.dbf datafile 4 switched to datafile copy input datafile copy RECID=30 STAMP=894988217 file name=/u01/oradata2/TESTDB/datafile/o1_mf_users_51qlgrqp_.dbf contents of Memory Script: { set until scn 2237265; recover clone database delete archivelog ; } executing Memory Script executing command: SET until clause Starting recover at 2015-11-05 15:48:46 allocated channel: ORA_AUX_DISK_1 channel ORA_AUX_DISK_1: SID=24 device type=DISK starting media recovery archived log for thread 1 with sequence 146 is already on disk as file /opt/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_146_894101903.dbf archived log file name=/opt/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_146_894101903.dbf thread=1 sequence=146 media recovery complete, elapsed time: 00:00:00 Finished recover at 2015-11-05 15:48:49 Oracle instance started Total System Global Area 238034944 bytes Fixed Size 2252016 bytes Variable Size 180355856 bytes Database Buffers 50331648 bytes Redo Buffers 5095424 bytes contents of Memory Script: { sql clone "alter system set db_name = ''TESTDB'' 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 Script sql statement: alter system set db_name = ''TESTDB'' comment= ''Reset to original value by RMAN'' scope=spfile sql statement: alter system reset db_unique_name scope=spfile Oracle instance shut down connected to auxiliary database (not started) Oracle instance started Total System Global Area 238034944 bytes Fixed Size 2252016 bytes Variable Size 180355856 bytes Database Buffers 50331648 bytes Redo Buffers 5095424 bytes sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TESTDB" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 SIZE 50 M , GROUP 2 SIZE 50 M , GROUP 3 SIZE 50 M DATAFILE '/u01/oradata2/TESTDB/datafile/o1_mf_system_4uqlgrpe_.dbf' CHARACTER SET ZHS16GBK contents of Memory Script: { set newname for clone tempfile 1 to new; switch clone tempfile all; catalog clone datafilecopy "/u01/oradata2/TESTDB/datafile/o1_mf_sysaux_4vqlgrq7_.dbf", "/u01/oradata2/TESTDB/datafile/o1_mf_undotbs1_50qlgrqm_.dbf", "/u01/oradata2/TESTDB/datafile/o1_mf_users_51qlgrqp_.dbf"; switch clone datafile all; } executing Memory Script executing command: SET NEWNAME renamed tempfile 1 to /u01/oradata2/TESTDB/datafile/o1_mf_temp_%u_.tmp in control file cataloged datafile copy datafile copy file name=/u01/oradata2/TESTDB/datafile/o1_mf_sysaux_4vqlgrq7_.dbf RECID=1 STAMP=894988259 cataloged datafile copy datafile copy file name=/u01/oradata2/TESTDB/datafile/o1_mf_undotbs1_50qlgrqm_.dbf RECID=2 STAMP=894988259 cataloged datafile copy datafile copy file name=/u01/oradata2/TESTDB/datafile/o1_mf_users_51qlgrqp_.dbf RECID=3 STAMP=894988259 datafile 2 switched to datafile copy input datafile copy RECID=1 STAMP=894988259 file name=/u01/oradata2/TESTDB/datafile/o1_mf_sysaux_4vqlgrq7_.dbf datafile 3 switched to datafile copy input datafile copy RECID=2 STAMP=894988259 file name=/u01/oradata2/TESTDB/datafile/o1_mf_undotbs1_50qlgrqm_.dbf datafile 4 switched to datafile copy input datafile copy RECID=3 STAMP=894988259 file name=/u01/oradata2/TESTDB/datafile/o1_mf_users_51qlgrqp_.dbf Reenabling controlfile options for auxiliary database Executing: alter database enable block change tracking contents of Memory Script: { Alter clone database open resetlogs; } executing Memory Script database opened Finished Duplicate Db at 2015-11-05 15:49:38 RMAN> |
5.打开辅助实例
登录到B机,
$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Thu Nov 5 16:06:29 2015 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, Real Application Clusters, OLAP, Data Mining and Real Application Testing options SQL> select status, instance_name from v$instance; STATUS INSTANCE_NAME ------------ ---------------- OPEN testdb SQL> select dbid, open_mode from v$database; DBID OPEN_MODE ---------- -------------------- 2678316385 READ WRITE |
至此,成功duplicate数据库TESTDB。可以发现使用RMAN DUPLICATE复制的数据库DBID是不同的。