你的位置:首页 > 数据库

[数据库]使用duplicate target database ... from active database复制数据库


使用duplicate target database ... from active database复制数据库

source db:ora11
auxiliary db:dupdb

1.修改监听文件,静态注册监听

SID_LIST_ORA11 =    (SID_LIST =      (SID_DESC =        (GLOBAL_DBNAME = ora11)        (ORACLE_HOME = /u11/app/oracle/product/11.2.0/dbhome_1)        (SID_NAME =ora11)      )      (SID_DESC =        (GLOBAL_DBNAME = dupdb)        (ORACLE_HOME = /u11/app/oracle/product/11.2.0/dbhome_1)        (SID_NAME =dupdb)      )    )

2.修改tnsnames.ora文件

ORA11 =  (DESCRIPTION =    (ADDRESS_LIST =      (ADDRESS = (PROTOCOL = TCP)(HOST = mytest)(PORT = 1521))    )      (CONNECT_DATA =        (SERVER = DEDICATED)        (SERVICE_NAME = ora11)      )    )    DUPDB =  (DESCRIPTION =    (ADDRESS_LIST =      (ADDRESS = (PROTOCOL = TCP)(HOST = mytest)(PORT = 1521))    )    (CONNECT_DATA =      (SERVER = DEDICATED)      (SERVICE_NAME = dupdb)    )  )

3.为duplicate 数据库创建参数文件initdupdb.ora

db_name=dupdb

4.创建口令文件

$ orapwd password=<sys_pwd> file=orapwtest1 entries=20

5.启动auxiliary 库

$ sqlplus /nologSQL*Plus: Release 11.2.0.1.0 Production on Fri Jun 26 12:28:26 2015Copyright (c) 1982, 2009, Oracle. All rights reserved.SQL> conn /as sysdbaConnected to an idle instance.SQL> startup nomount pfile='/u11/app/oracle/product/11.2.0/dbhome_1/dbs/initdupdb.ora';ORACLE instance started.Total System Global Area 217157632 bytesFixed Size         2211928 bytesVariable Size       159387560 bytesDatabase Buffers      50331648 bytesRedo Buffers        5226496 bytesSQL> 

6.启动rman

$ rman Recovery Manager: Release 11.2.0.1.0 - Production on Fri Jun 26 12:31:07 2015Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.RMAN> connect target sys/oracle@ora11connected to target database: ORA11 (DBID=785451981)RMAN> connect auxiliary /connected to auxiliary database: DUPDB (not mounted)RMAN> 

7.执行duplicate target database ... from active database 命令开始duplicate操作

RMAN> duplicate target database to dupdb from active database2> spfile 3>   parameter_value_convert='/u11/app/oracle/oradata/ora11','/u11/app/oracle/oradata/dupdb'4>   set 5>       log_file_name_convert='/u11/app/oracle/oradata/ora11','/u11/app/oracle/oradata/dupdb'6>       db_file_name_convert='/u11/app/oracle/oradata/ora11','/u11/app/oracle/oradata/dupdb';Starting Duplicate Db at 26-JUN-2015 14:16:31using target database control file instead of recovery catalogallocated channel: ORA_AUX_DISK_1channel ORA_AUX_DISK_1: SID=19 device type=DISKcontents of Memory Script:{  backup as copy reuse  targetfile '/u11/app/oracle/product/11.2.0/dbhome_1/dbs/spfileora11.ora' auxiliary format '/u11/app/oracle/product/11.2.0/dbhome_1/dbs/spfiledupdb.ora'  ;  sql clone "alter system set spfile= ''/u11/app/oracle/product/11.2.0/dbhome_1/dbs/spfiledupdb.ora''";}executing Memory ScriptStarting backup at 26-JUN-2015 14:16:32allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=37 device type=DISKFinished backup at 26-JUN-2015 14:16:33sql statement: alter system set spfile= ''/u11/app/oracle/product/11.2.0/dbhome_1/dbs/spfiledupdb.ora''contents of Memory Script:{  sql clone "alter system set db_name =  ''DUPDB'' comment= ''duplicate'' scope=spfile";  sql clone "alter system set control_files =  ''/u11/app/oracle/oradata/dupdb/control01.ctl'', ''/u11/app/oracle/oradata/dupdb/control02.ctl'' comment= '''' scope=spfile";  sql clone "alter system set log_file_name_convert =  ''/u11/app/oracle/oradata/ora11'', ''/u11/app/oracle/oradata/dupdb'' comment= '''' scope=spfile";  shutdown clone immediate;  startup clone nomount;}executing Memory Scriptsql statement: alter system set db_name = ''DUPDB'' comment= ''duplicate'' scope=spfilesql statement: alter system set control_files = ''/u11/app/oracle/oradata/dupdb/control01.ctl'', ''/u11/app/oracle/oradata/dupdb/control02.ctl'' comment= '''' scope=spfilesql statement: alter system set log_file_name_convert = ''/u11/app/oracle/oradata/ora11'', ''/u11/app/oracle/oradata/dupdb'' comment= '''' scope=spfileOracle instance shut downconnected to auxiliary database (not started)Oracle instance startedTotal System Global Area   630501376 bytesFixed Size           2215984 bytesVariable Size        184553424 bytesDatabase Buffers       440401920 bytesRedo Buffers          3330048 bytescontents of Memory Script:{  sql clone "alter system set db_name =  ''ORA11'' 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  backup as copy current controlfile auxiliary format '/u11/app/oracle/oradata/dupdb/control01.ctl';  restore clone controlfile to '/u11/app/oracle/oradata/dupdb/control02.ctl' from '/u11/app/oracle/oradata/dupdb/control01.ctl';  alter clone database mount;}executing Memory Scriptsql statement: alter system set db_name = ''ORA11'' 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   630501376 bytesFixed Size           2215984 bytesVariable Size        184553424 bytesDatabase Buffers       440401920 bytesRedo Buffers          3330048 bytesStarting backup at 26-JUN-2015 14:16:45using channel ORA_DISK_1channel ORA_DISK_1: starting datafile copycopying current control fileoutput file name=/u11/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_ora11.f tag=TAG20150626T141645 RECID=21 STAMP=883405007channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03Finished backup at 26-JUN-2015 14:16:49Starting restore at 26-JUN-2015 14:16:49allocated channel: ORA_AUX_DISK_1channel ORA_AUX_DISK_1: SID=19 device type=DISKchannel ORA_AUX_DISK_1: copied control file copyFinished restore at 26-JUN-2015 14:16:50database mountedcontents of Memory Script:{  set newname for datafile 1 to "/u11/app/oracle/oradata/dupdb/system01.dbf";  set newname for datafile 2 to "/u11/app/oracle/oradata/dupdb/sysaux01.dbf";  set newname for datafile 3 to "/u11/app/oracle/oradata/dupdb/yb01.dbf";  set newname for datafile 4 to "/u11/app/oracle/oradata/dupdb/users01.dbf";  set newname for datafile 5 to "/u11/app/oracle/oradata/dupdb/example01.dbf";  set newname for datafile 6 to "/u11/app/oracle/oradata/dupdb/UNDOTBS02.dbf";  backup as copy reuse  datafile 1 auxiliary format "/u11/app/oracle/oradata/dupdb/system01.dbf"  datafile 2 auxiliary format "/u11/app/oracle/oradata/dupdb/sysaux01.dbf"  datafile 3 auxiliary format "/u11/app/oracle/oradata/dupdb/yb01.dbf"  datafile 4 auxiliary format "/u11/app/oracle/oradata/dupdb/users01.dbf"  datafile 5 auxiliary format "/u11/app/oracle/oradata/dupdb/example01.dbf"  datafile 6 auxiliary format "/u11/app/oracle/oradata/dupdb/UNDOTBS02.dbf"  ;  sql 'alter system archive log current';}executing Memory Scriptexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEStarting backup at 26-JUN-2015 14:16:55using channel ORA_DISK_1channel ORA_DISK_1: starting datafile copyinput datafile file number=00001 name=/u11/app/oracle/oradata/ora11/system01.dbfoutput file name=/u11/app/oracle/oradata/dupdb/system01.dbf tag=TAG20150626T141655channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35channel ORA_DISK_1: starting datafile copyinput datafile file number=00002 name=/u11/app/oracle/oradata/ora11/sysaux01.dbfoutput file name=/u11/app/oracle/oradata/dupdb/sysaux01.dbf tag=TAG20150626T141655channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35channel ORA_DISK_1: starting datafile copyinput datafile file number=00005 name=/u11/app/oracle/oradata/ora11/example01.dbfoutput file name=/u11/app/oracle/oradata/dupdb/example01.dbf tag=TAG20150626T141655channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07channel ORA_DISK_1: starting datafile copyinput datafile file number=00006 name=/u11/app/oracle/oradata/ora11/UNDOTBS02.dbfoutput file name=/u11/app/oracle/oradata/dupdb/UNDOTBS02.dbf tag=TAG20150626T141655channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07channel ORA_DISK_1: starting datafile copyinput datafile file number=00003 name=/u11/app/oracle/oradata/ora11/yb01.dbfoutput file name=/u11/app/oracle/oradata/dupdb/yb01.dbf tag=TAG20150626T141655channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03channel ORA_DISK_1: starting datafile copyinput datafile file number=00004 name=/u11/app/oracle/oradata/ora11/users01.dbfoutput file name=/u11/app/oracle/oradata/dupdb/users01.dbf tag=TAG20150626T141655channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01Finished backup at 26-JUN-2015 14:18:24sql statement: alter system archive log currentcontents of Memory Script:{  backup as copy reuse  archivelog like "/u11/app/oracle/fra/ORA11/archivelog/2015_06_26/o1_mf_1_98_brsvojfz_.arc" auxiliary format "/u11/app/oracle/fra/DUPDB/archivelog/2015_06_26/o1_mf_1_98_%u_.arc"  ;  catalog clone recovery area;  switch clone datafile all;}executing Memory ScriptStarting backup at 26-JUN-2015 14:18:25using channel ORA_DISK_1channel ORA_DISK_1: starting archived log copyinput archived log thread=1 sequence=98 RECID=91 STAMP=883405104output file name=/u11/app/oracle/fra/DUPDB/archivelog/2015_06_26/o1_mf_1_98_4mqafc9h_.arc RECID=0 STAMP=0channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01Finished backup at 26-JUN-2015 14:18:26searching for all files in the recovery areaList of Files Unknown to the Database=====================================File Name: /u11/app/oracle/fra/DUPDB/archivelog/2015_06_26/o1_mf_1_98_4mqafc9h_.arccataloging files...cataloging doneList of Cataloged Files=======================File Name: /u11/app/oracle/fra/DUPDB/archivelog/2015_06_26/o1_mf_1_98_4mqafc9h_.arcdatafile 1 switched to datafile copyinput datafile copy RECID=21 STAMP=883405107 file name=/u11/app/oracle/oradata/dupdb/system01.dbfdatafile 2 switched to datafile copyinput datafile copy RECID=22 STAMP=883405107 file name=/u11/app/oracle/oradata/dupdb/sysaux01.dbfdatafile 3 switched to datafile copyinput datafile copy RECID=23 STAMP=883405107 file name=/u11/app/oracle/oradata/dupdb/yb01.dbfdatafile 4 switched to datafile copyinput datafile copy RECID=24 STAMP=883405107 file name=/u11/app/oracle/oradata/dupdb/users01.dbfdatafile 5 switched to datafile copyinput datafile copy RECID=25 STAMP=883405107 file name=/u11/app/oracle/oradata/dupdb/example01.dbfdatafile 6 switched to datafile copyinput datafile copy RECID=26 STAMP=883405107 file name=/u11/app/oracle/oradata/dupdb/UNDOTBS02.dbfcontents of Memory Script:{  set until scn 1432824;  recover  clone database  delete archivelog  ;}executing Memory Scriptexecuting command: SET until clauseStarting recover at 26-JUN-2015 14:18:27using channel ORA_AUX_DISK_1starting media recoveryarchived log for thread 1 with sequence 98 is already on disk as file /u11/app/oracle/fra/DUPDB/archivelog/2015_06_26/o1_mf_1_98_4mqafc9h_.arcarchived log file name=/u11/app/oracle/fra/DUPDB/archivelog/2015_06_26/o1_mf_1_98_4mqafc9h_.arc thread=1 sequence=98media recovery complete, elapsed time: 00:00:00Finished recover at 26-JUN-2015 14:18:28contents of Memory Script:{  shutdown clone immediate;  startup clone nomount;  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 Scriptdatabase dismountedOracle instance shut downconnected to auxiliary database (not started)Oracle instance startedTotal System Global Area   630501376 bytesFixed Size           2215984 bytesVariable Size        184553424 bytesDatabase Buffers       440401920 bytesRedo Buffers          3330048 bytessql 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   630501376 bytesFixed Size           2215984 bytesVariable Size        184553424 bytesDatabase Buffers       440401920 bytesRedo Buffers          3330048 bytessql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG  MAXLOGFILES   16 MAXLOGMEMBERS   3 MAXDATAFILES   100 MAXINSTANCES   8 MAXLOGHISTORY   292 LOGFILE GROUP 1 ( '/u11/app/oracle/oradata/dupdb/redo01.log', '/u11/app/oracle/oradata/dupdb/redo01b.log' ) SIZE 50 M REUSE, GROUP 2 ( '/u11/app/oracle/oradata/dupdb/redo02b.log', '/u11/app/oracle/oradata/dupdb/redo02.log' ) SIZE 50 M REUSE, GROUP 3 ( '/u11/app/oracle/oradata/dupdb/redo03b.log', '/u11/app/oracle/oradata/dupdb/redo03.log' ) SIZE 50 M REUSE DATAFILE '/u11/app/oracle/oradata/dupdb/system01.dbf' CHARACTER SET AL32UTF8contents of Memory Script:{  set newname for tempfile 1 to "/u11/app/oracle/oradata/dupdb/temp01.dbf";  switch clone tempfile all;  catalog clone datafilecopy "/u11/app/oracle/oradata/dupdb/sysaux01.dbf", "/u11/app/oracle/oradata/dupdb/yb01.dbf", "/u11/app/oracle/oradata/dupdb/users01.dbf", "/u11/app/oracle/oradata/dupdb/example01.dbf", "/u11/app/oracle/oradata/dupdb/UNDOTBS02.dbf";  switch clone datafile all;}executing Memory Scriptexecuting command: SET NEWNAMErenamed tempfile 1 to /u11/app/oracle/oradata/dupdb/temp01.dbf in control filecataloged datafile copydatafile copy file name=/u11/app/oracle/oradata/dupdb/sysaux01.dbf RECID=1 STAMP=883405119cataloged datafile copydatafile copy file name=/u11/app/oracle/oradata/dupdb/yb01.dbf RECID=2 STAMP=883405119cataloged datafile copydatafile copy file name=/u11/app/oracle/oradata/dupdb/users01.dbf RECID=3 STAMP=883405119cataloged datafile copydatafile copy file name=/u11/app/oracle/oradata/dupdb/example01.dbf RECID=4 STAMP=883405119cataloged datafile copydatafile copy file name=/u11/app/oracle/oradata/dupdb/UNDOTBS02.dbf RECID=5 STAMP=883405119datafile 2 switched to datafile copyinput datafile copy RECID=1 STAMP=883405119 file name=/u11/app/oracle/oradata/dupdb/sysaux01.dbfdatafile 3 switched to datafile copyinput datafile copy RECID=2 STAMP=883405119 file name=/u11/app/oracle/oradata/dupdb/yb01.dbfdatafile 4 switched to datafile copyinput datafile copy RECID=3 STAMP=883405119 file name=/u11/app/oracle/oradata/dupdb/users01.dbfdatafile 5 switched to datafile copyinput datafile copy RECID=4 STAMP=883405119 file name=/u11/app/oracle/oradata/dupdb/example01.dbfdatafile 6 switched to datafile copyinput datafile copy RECID=5 STAMP=883405119 file name=/u11/app/oracle/oradata/dupdb/UNDOTBS02.dbfcontents of Memory Script:{  Alter clone database open resetlogs;}executing Memory Scriptdatabase openedFinished Duplicate Db at 26-JUN-2015 14:19:00RMAN> 

 

完成!