在Oracle 10g下,我们可以使用RMAN duplicate 命令创建一个具有不同DBID 的复制库。 到了Oracle 11gR2, RMAN 的duplicate 有2种方法实现:
1. Active database duplication 2. Backup-based duplication Active database duplication 通过网络,直接copy target 库到auxiliary 库,然后创建复制库。 这种方法就不需要先用RMAN 备份数据库,然后将备份文件发送到auxiliary端。 这个功能的作用是非常大的。 尤其是对T级别的库。 因为对这样的库进行备份,然后将备份集发送到备库,在进行duplicate 的代价是非常大的。 一备份要占用时间,二要占用备份空间,三在网络传送的时候,还需要占用带宽和时间。所以Active database duplicate 很好的解决了以上的问题。 它对大库的迁移非常有用。 如果是从RAC duplicate 到单实例,操作是一样的。 如果是从单实例duplicate 到RAC。 那么先duplicate 到 单实例。 然后将单实例转换成RAC。 下面我们看一下11gR2下,Active Database Duplicate的步骤如下:1. 创建Auxiliary 库的Initialization Parameter: 如果使用spfile,那么在pfile文件里只需要设置一个DB_NAME参数,其他参数会在duplicate 命令中自己设置。 如果使用pfile,那么需要设置如下参数: DB_NAME CONTROL_FILES DB_BLOCK_SIZE DB_FILE_NAME_CONVERT LOG_FILE_NAME_CONVERT DB_RECOVERY_FILE_DEST2. 在Auxiliary库创建Password File 文件 对于Backup-based duplication,Password File 不是必须的,但是对于Active Database Duplication,Password File是必须的。 因为Active Database Duplication 使用相同的SYSDBA 密码直接连接到auxiliary 库。 所以,确保target 和Auxiliary库的SYSDBA 密码一样很重要。 当然,我们也可以在duplicate 命令中加上PASSWORD FILE 选项(也是默认值), 这样RMAN 在copy 的时候也会从target 库把密码文件copy过来,如果auxiliary库上已经存在了Password file,那么该操作会重写那个文件。如:RMAN> DUPLICATE TARGET DATABASE TO Dave2> FROM ACTIVE DATABASE3> NOFILENAMECHECK4> PASSWORD FILE5> SPFILE;3. 如果是windows 平台,还需要创建Database service:% set ORACLE_SID=DAVE% set ORACLE_HOME=E:/oracle/product/11.1.0/db_1% oradim -NEW -SID DAVE 4. 配置oracle net,修改listener.ora和the tnsnames.ora 文件:在Target 库和Auxiliary 都要修改。这个也可以使用netca 和netmgr命令配置。Listener.ora[oracle@qs-dmm-rh1 admin]$ cat listener.ora LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost6.localdomain6)(PORT = 1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracleSID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = orcl) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) (SID_NAME = orcl) ) )tnsname.ora[oracle@qs-dmm-rh1 admin]$ cat tnsnames.ora ORCL_ST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.43)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) )ORCL_PD = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.42)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) )5. 用第一步创建的pfile文件,将Auxiliary启动到nomout 状态。 然后进行Active Database duplicate。我们看一个完整的复制示例:Target DB:IP: 192.168.2.42SID:orclAuxiliary:IP:192.168.2.43SID:orcl我这里复制的目录相同。 如果不同的话需要在pfile里面加入db_file_name_convert和log_file_name_convert. 1. 在Auxiliary 创建pfile 参数文件:[oracle@qs-dmm-rh2 dbs]$ pwd/u01/app/oracle/product/11.2.0/dbhome_1/dbs[oracle@qs-dmm-rh2 dbs]$ cat initorcl.ora DB_NAME=orcl只有一个参数: DB_NAME2. 在Auxiliary库上创建口令文件[oracle@qs-dmm-rh2 admin]$ orapwd file=?/dbs/orapworcl password=oracle3. 在Auxiliary库创建相关的目录结构:[oracle@qs-dmm-rh2 trace]$ mkdir -p /u01/app/oracle/oradata/orcl不然在duplicate时会报如下错误:ORA-19505: failed to identify file "/u01/app/oracle/oradata/orcl/users01.dbf"ORA-27040: file create error, unable to create file4. 启动Auxiliary 到nomout 状态:[oracle@qs-dmm-rh2 admin]$ sqlplus /nologSQL*Plus: Release 11.2.0.1.0 Production on Tue Mar 8 00:28:48 2011Copyright (c) 1982, 2009, Oracle. All rights reserved.SQL> conn / as sysdba;Connected to an idle instance.SQL> startup nomount pfile=?/dbs/initorcl.oraORACLE instance started.Total System Global Area 146472960 bytesFixed Size 1335080 bytesVariable Size 92274904 bytesDatabase Buffers 50331648 bytesRedo Buffers 2531328 bytesSQL>5. 在Target 和Auxiliary 都配置Oracle Net(Listener.ora and tnsnames.ora):[oracle@qs-dmm-rh1 admin]$ cat listener.ora LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost6.localdomain6)(PORT = 1521)) ) )ADR_BASE_LISTENER = /u01/app/oracleSID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = orcl) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1) (SID_NAME = orcl) ) )[oracle@qs-dmm-rh1 admin]$ cat tnsnames.ora ORCL_ST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.43)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) )ORCL_PD = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.42)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) )6. 开始RMAN duplicate from active database: 注意:如果target 和 Auxiliary库的目录结构相同,记得加上nofilenamecheck参数,不然会报如下错误: RMAN-05001: auxiliary file name /u01/app/oracle/oradata/orcl/users01.dbf conflicts with a file used by the target database 如果目录不同,在pfile里加如下2个参数进行转换: db_file_name_convert log_file_name_convert[oracle@qs-dmm-rh2 dbs]$ rman target sys/oracle@orcl_pd auxiliary sys/oracle@orcl_stRecovery Manager: Release 11.2.0.1.0 - Production on Tue Mar 8 01:01:42 2011Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reservedconnected to target database: ORCL (DBID=1272955137)connected to auxiliary database: ORCL (not mounted)RMAN> duplicate target database to orcl from active database nofilenamecheck;Starting Duplicate Db at 08-MAR-11using target database control file instead of recovery catalogallocated channel: ORA_AUX_DISK_1channel ORA_AUX_DISK_1: SID=20 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 starteTotal System Global Area 146472960 bytesFixed Size 1335080 bytesVariable Size 92274904 bytesDatabase Buffers 50331648 bytesRedo Buffers 2531328 bytescontents of Memory Script:{ sql clone "alter system set db_name = ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile"; sql clone "alter system set db_unique_name = ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfile"; shutdown clone immediate; startup clone force nomount backup as copy current controlfile auxiliary format '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/cntrlorcl.dbf'; alter clone database mount;}executing Memory Scriptsql statement: alter system set db_name = ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfilesql statement: alter system set db_unique_name = ''ORCL'' comment= ''Modified by RMAN duplicate'' scope=spfileOracle instance shut downOracle instance startedTotal System Global Area 146472960 bytesFixed Size 1335080 bytesVariable Size 92274904 bytesDatabase Buffers 50331648 bytesRedo Buffers 2531328 bytesStarting backup at 08-MAR-11allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=43 device type=DISKchannel ORA_DISK_1: starting datafile copycopying current control fileoutput file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f tag=TAG20110308T010214 RECID=3 STAMP=745203735channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01Finished backup at 08-MAR-11database mountedcontents of Memory Script:{ set newname for datafile 1 to "/u01/app/oracle/oradata/orcl/system01.dbf"; set newname for datafile 2 to "/u01/app/oracle/oradata/orcl/sysaux01.dbf"; set newname for datafile 3 to "/u01/app/oracle/oradata/orcl/undotbs01.dbf"; set newname for datafile 4 to "/u01/app/oracle/oradata/orcl/users01.dbf"; backup as copy reuse datafile 1 auxiliary format "/u01/app/oracle/oradata/orcl/system01.dbf" datafile 2 auxiliary format "/u01/app/oracle/oradata/orcl/sysaux01.dbf" datafile 3 auxiliary format "/u01/app/oracle/oradata/orcl/undotbs01.dbf" datafile 4 auxiliary format "/u01/app/oracle/oradata/orcl/users01.dbf" ; sql 'alter system archive log current';}executing Memory Script executing command: SET NEWNAMEusing channel ORA_DISK_1channel ORA_DISK_1: starting datafile copy--在这里开始copy 数据文件,比较慢。input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbfoutput file name=/u01/app/oracle/oradata/orcl/system01.dbf tag=TAG20110308T010221channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45channel ORA_DISK_1: starting datafile copyinput datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbfoutput file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf tag=TAG20110308T010221channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35channel ORA_DISK_1: starting datafile copyinput datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbfoutput file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf tag=TAG20110308T010221channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15channel ORA_DISK_1: starting datafile copyinput datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbfoutput file name=/u01/app/oracle/oradata/orcl/users01.dbf tag=TAG20110308T010221channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01Finished backup at 08-MAR-11sql statement: alter system archive log currentcontents of Memory Script:{ backup as copy reuse archivelog like "/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_03_08/o1_mf_1_7_6qb3zyoo_.arc" auxiliary format "/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf" ; catalog clone archivelog "/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf"; switch clone datafile all;}executing Memory ScriptStarting backup at 08-MAR-11using channel ORA_DISK_1channel ORA_DISK_1: starting archived log copyinput archived log thread=1 sequence=7 RECID=3 STAMP=745203841output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf RECID=0 STAMP=0channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:07Finished backup at 08-MAR-1 cataloged archived logarchived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf RECID=3 STAMP=745203848 datafile 1 switched to datafile copyinput datafile copy RECID=3 STAMP=745203849 file name=/u01/app/oracle/oradata/orcl/system01.dbfdatafile 2 switched to datafile copyinput datafile copy RECID=4 STAMP=745203849 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbfdatafile 3 switched to datafile copyinput datafile copy RECID=5 STAMP=745203849 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbfdatafile 4 switched to datafile copyinput datafile copy RECID=6 STAMP=745203849 file name=/u01/app/oracle/oradata/orcl/users01.dbf contents of Memory Script:{ set until scn 844147; recover clone database delete archivelog;}executing Memory Scriptexecuting command: SET until clauseStarting recover at 08-MAR-11allocated channel: ORA_AUX_DISK_1channel ORA_AUX_DISK_1: SID=18 device type=DISKstarting media recoveryarchived log for thread 1 with sequence 7 is already on disk as file /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbfarchived log file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf thread=1 sequence=7media recovery complete, elapsed time: 00:00:01Finished recover at 08-MAR-11contents of Memory Script:{ shutdown clone immediate; startup clone nomount; sql clone "alter system set db_name = ''ORCL'' 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 146472960 bytesFixed Size 1335080 bytesVariable Size 92274904 bytesDatabase Buffers 50331648 bytesRedo Buffers 2531328 bytessql statement: alter system set db_name = ''ORCL'' 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 146472960 byteFixed Size 1335080 bytesVariable Size 92274904 bytesDatabase Buffers 50331648 bytesRedo Buffers 2531328 bytessql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 ( '/u01/app/oracle/oradata/orcl/redo01.log' ) SIZE 50 M REUSE, GROUP 2 ( '/u01/app/oracle/oradata/orcl/redo02.log' ) SIZE 50 M REUSE, GROUP 3 ( '/u01/app/oracle/oradata/orcl/redo03.log' ) SIZE 50 M REUSE DATAFILE '/u01/app/oracle/oradata/orcl/system01.dbf' CHARACTER SET ZHS16GBKcontents of Memory Script:{ set newname for tempfile 1 to "/u01/app/oracle/oradata/orcl/temp01.dbf"; switch clone tempfile all; catalog clone datafilecopy "/u01/app/oracle/oradata/orcl/sysaux01.dbf", "/u01/app/oracle/oradata/orcl/undotbs01.dbf", "/u01/app/oracle/oradata/orcl/users01.dbf"; switch clone datafile all;}executing Memory Scriptexecuting command: SET NEWNAMErenamed tempfile 1 to /u01/app/oracle/oradata/orcl/temp01.dbf in control filecataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/orcl/sysaux01.dbf RECID=1 STAMP=745203867cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/orcl/undotbs01.dbf RECID=2 STAMP=745203867cataloged datafile copydatafile copy file name=/u01/app/oracle/oradata/orcl/users01.dbf RECID=3 STAMP=745203867 datafile 2 switched to datafile copyinput datafile copy RECID=1 STAMP=745203867 file name=/u01/app/oracle/oradata/orcl/sysaux01.dbfdatafile 3 switched to datafile copyinput datafile copy RECID=2 STAMP=745203867 file name=/u01/app/oracle/oradata/orcl/undotbs01.dbfdatafile 4 switched to datafile copyinput datafile copy RECID=3 STAMP=745203867 file name=/u01/app/oracle/oradata/orcl/users01.dbfcontents of Memory Script:{ Alter clone database open resetlogs;}executing Memory Scriptdatabase openedFinished Duplicate Db at 08-MAR-11RMAN>复制结束。 查询:Target 库:SQL> select name,dbid from v$database;NAME DBID--------- ----------ORCL 1272955137Auxiliary库:SQL> select name,dbid from v$database; NAME DBID--------- ----------ORCL 1272984602