Oracle 11gR2 使用 RMAN duplicate from active database 复制数据库

Oracle10g下,我们可以使用RMANduplicate命令创建一个具有不同DBID的复制库。到了Oracle11gR2RMANduplicate2种方法实现:

1.Activedatabaseduplication

2.Backup-basedduplication

Activedatabaseduplication通过网络,直接copytarget库到auxiliary库,然后创建复制库。这种方法就不需要先用RMAN备份数据库,然后将备份文件发送到auxiliary端。

这个功能的作用是非常大的。尤其是对T级别的库。因为对这样的库进行备份,然后将备份集发送到备库,在进行duplicate的代价是非常大的。一备份要占用时间,二要占用备份空间,三在网络传送的时候,还需要占用带宽和时间。所以Activedatabaseduplicate很好的解决了以上的问题。它对大库的迁移非常有用。

如果是从RACduplicate到单实例,操作是一样的。如果是从单实例duplicateRAC那么先duplicate单实例。然后将单实例转换成RAC

下面我们看一下11gR2下,ActiveDatabaseDuplicate的步骤如下:

1.创建Auxiliary库的InitializationParameter

如果使用spfile,那么在pfile文件里只需要设置一个DB_NAME参数,其他参数会在duplicate命令中自己设置。

如果使用pfile,那么需要设置如下参数:

DB_NAME

CONTROL_FILES

DB_BLOCK_SIZE

DB_FILE_NAME_CONVERT

LOG_FILE_NAME_CONVERT

DB_RECOVERY_FILE_DEST

2.Auxiliary库创建PasswordFile文件

对于Backup-basedduplicationPasswordFile不是必须的,但是对于ActiveDatabaseDuplicationPasswordFile是必须的。因为ActiveDatabaseDuplication使用相同的SYSDBA密码直接连接到auxiliary库。所以,确保targetAuxiliary库的SYSDBA密码一样很重要。

当然,我们也可以在duplicate命令中加上PASSWORDFILE选项(也是默认值),这样RMANcopy的时候也会从target库把密码文件copy过来,如果auxiliary库上已经存在了Passwordfile,那么该操作会重写那个文件。

如:

RMAN>DUPLICATETARGETDATABASETODave

2>FROMACTIVEDATABASE

3>NOFILENAMECHECK

4>PASSWORDFILE

5>SPFILE;

3.如果是windows平台,还需要创建Databaseservice

%setORACLE_SID=DAVE
%setORACLE_HOME=E:/oracle/product/11.1.0/db_1
%oradim-NEW-SIDDAVE

4.配置oraclenet,修改listener.orathetnsnames.ora文件:

Target库和Auxiliary都要修改。这个也可以使用netcanetmgr命令配置。

Listener.ora

[oracle@qs-dmm-rh1admin]$catlistener.ora

LISTENER=

(DESCRIPTION_LIST=

(DESCRIPTION=

(ADDRESS=(PROTOCOL=TCP)(HOST=localhost6.localdomain6)(PORT=1521))

)

)

ADR_BASE_LISTENER=/u01/app/oracle

SID_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-rh1admin]$cattnsnames.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状态。然后进行ActiveDatabaseduplicate

我们看一个完整的复制示例:

TargetDB

IP:192.168.2.42

SIDorcl

Auxiliary

IP192.168.2.43

SID:orcl

我这里复制的目录相同。如果不同的话需要在pfile里面加入db_file_name_convertlog_file_name_convert.

1.Auxiliary创建pfile参数文件:

[oracle@qs-dmm-rh2dbs]$pwd

/u01/app/oracle/product/11.2.0/dbhome_1/dbs

[oracle@qs-dmm-rh2dbs]$catinitorcl.ora

DB_NAME=orcl

只有一个参数:DB_NAME

2.Auxiliary库上创建口令文件

[oracle@qs-dmm-rh2admin]$orapwdfile=?/dbs/orapworclpassword=oracle

3.Auxiliary库创建相关的目录结构:

[oracle@qs-dmm-rh2trace]$mkdir-p/u01/app/oracle/oradata/orcl

不然在duplicate时会报如下错误:

ORA-19505:failedtoidentifyfile"/u01/app/oracle/oradata/orcl/users01.dbf"

ORA-27040:filecreateerror,unabletocreatefile

4.启动Auxiliarynomout状态:

[oracle@qs-dmm-rh2admin]$sqlplus/nolog

SQL*Plus:Release11.2.0.1.0ProductiononTueMar800:28:482011

Copyright(c)1982,2009,Oracle.Allrightsreserved.

SQL>conn/assysdba;

Connectedtoanidleinstance.

SQL>startupnomountpfile=?/dbs/initorcl.ora

ORACLEinstancestarted.

TotalSystemGlobalArea146472960bytes

FixedSize1335080bytes

VariableSize92274904bytes

DatabaseBuffers50331648bytes

RedoBuffers2531328bytes

SQL>

5.TargetAuxiliary都配置OracleNetListener.oraandtnsnames.ora):

[oracle@qs-dmm-rh1admin]$catlistener.ora

LISTENER=

(DESCRIPTION_LIST=

(DESCRIPTION=

(ADDRESS=(PROTOCOL=TCP)(HOST=localhost6.localdomain6)(PORT=1521))

)

)

ADR_BASE_LISTENER=/u01/app/oracle

SID_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-rh1admin]$cattnsnames.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.开始RMANduplicatefromactivedatabase

注意:如果targetAuxiliary库的目录结构相同,记得加上nofilenamecheck参数,不然会报如下错误:

RMAN-05001:auxiliaryfilename/u01/app/oracle/oradata/orcl/users01.dbfconflictswithafileusedbythetargetdatabase

如果目录不同,在pfile里加如下2个参数进行转换:

db_file_name_convert

log_file_name_convert.

[oracle@qs-dmm-rh2dbs]$rmantargetsys/oracle@orcl_pdauxiliarysys/oracle@orcl_st

RecoveryManager:Release11.2.0.1.0-ProductiononTueMar801:01:422011

Copyright(c)1982,2009,Oracleand/oritsaffiliates.Allrightsreserved.

connectedtotargetdatabase:ORCL(DBID=1272955137)

connectedtoauxiliarydatabase:ORCL(notmounted)

RMAN>duplicatetargetdatabasetoorclfromactivedatabasenofilenamecheck;

StartingDuplicateDbat08-MAR-11

usingtargetdatabasecontrolfileinsteadofrecoverycatalog

allocatedchannel:ORA_AUX_DISK_1

channelORA_AUX_DISK_1:SID=20devicetype=DISK

contentsofMemoryScript:

{

sqlclone"createspfilefrommemory";

}

executingMemoryScript

sqlstatement:createspfilefrommemory

contentsofMemoryScript:

{

shutdowncloneimmediate;

startupclonenomount;

}

executingMemoryScript

Oracleinstanceshutdown

connectedtoauxiliarydatabase(notstarted)

Oracleinstancestarted

TotalSystemGlobalArea146472960bytes

FixedSize1335080bytes

VariableSize92274904bytes

DatabaseBuffers50331648bytes

RedoBuffers2531328bytes

contentsofMemoryScript:

{

sqlclone"altersystemsetdb_name=

''ORCL''comment=

''ModifiedbyRMANduplicate''scope=spfile";

sqlclone"altersystemsetdb_unique_name=

''ORCL''comment=

''ModifiedbyRMANduplicate''scope=spfile";

shutdowncloneimmediate;

startupcloneforcenomount

backupascopycurrentcontrolfileauxiliaryformat'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/cntrlorcl.dbf';

alterclonedatabasemount;

}

executingMemoryScript

sqlstatement:altersystemsetdb_name=''ORCL''comment=''ModifiedbyRMANduplicate''scope=spfile

sqlstatement:altersystemsetdb_unique_name=''ORCL''comment=''ModifiedbyRMANduplicate''scope=spfile

Oracleinstanceshutdown

Oracleinstancestarted

TotalSystemGlobalArea146472960bytes

FixedSize1335080bytes

VariableSize92274904bytes

DatabaseBuffers50331648bytes

RedoBuffers2531328bytes

Startingbackupat08-MAR-11

allocatedchannel:ORA_DISK_1

channelORA_DISK_1:SID=43devicetype=DISK

channelORA_DISK_1:startingdatafilecopy

copyingcurrentcontrolfile

outputfilename=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_orcl.ftag=TAG20110308T010214RECID=3STAMP=745203735

channelORA_DISK_1:datafilecopycomplete,elapsedtime:00:00:01

Finishedbackupat08-MAR-11

databasemounted

contentsofMemoryScript:

{

setnewnamefordatafile1to

"/u01/app/oracle/oradata/orcl/system01.dbf";

setnewnamefordatafile2to

"/u01/app/oracle/oradata/orcl/sysaux01.dbf";

setnewnamefordatafile3to

"/u01/app/oracle/oradata/orcl/undotbs01.dbf";

setnewnamefordatafile4to

"/u01/app/oracle/oradata/orcl/users01.dbf";

backupascopyreuse

datafile1auxiliaryformat

"/u01/app/oracle/oradata/orcl/system01.dbf"datafile

2auxiliaryformat

"/u01/app/oracle/oradata/orcl/sysaux01.dbf"datafile

3auxiliaryformat

"/u01/app/oracle/oradata/orcl/undotbs01.dbf"datafile

4auxiliaryformat

"/u01/app/oracle/oradata/orcl/users01.dbf";

sql'altersystemarchivelogcurrent';

}

executingMemoryScript

executingcommand:SETNEWNAME

executingcommand:SETNEWNAME

executingcommand:SETNEWNAME

executingcommand:SETNEWNAME

Startingbackupat08-MAR-11

usingchannelORA_DISK_1

channelORA_DISK_1:startingdatafilecopy

--在这里开始copy数据文件,比较慢。

inputdatafilefilenumber=00001name=/u01/app/oracle/oradata/orcl/system01.dbf

outputfilename=/u01/app/oracle/oradata/orcl/system01.dbftag=TAG20110308T010221

channelORA_DISK_1:datafilecopycomplete,elapsedtime:00:00:45

channelORA_DISK_1:startingdatafilecopy

inputdatafilefilenumber=00002name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

outputfilename=/u01/app/oracle/oradata/orcl/sysaux01.dbftag=TAG20110308T010221

channelORA_DISK_1:datafilecopycomplete,elapsedtime:00:00:35

channelORA_DISK_1:startingdatafilecopy

inputdatafilefilenumber=00003name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

outputfilename=/u01/app/oracle/oradata/orcl/undotbs01.dbftag=TAG20110308T010221

channelORA_DISK_1:datafilecopycomplete,elapsedtime:00:00:15

channelORA_DISK_1:startingdatafilecopy

inputdatafilefilenumber=00004name=/u01/app/oracle/oradata/orcl/users01.dbf

outputfilename=/u01/app/oracle/oradata/orcl/users01.dbftag=TAG20110308T010221

channelORA_DISK_1:datafilecopycomplete,elapsedtime:00:00:01

Finishedbackupat08-MAR-11

sqlstatement:altersystemarchivelogcurrent

contentsofMemoryScript:

{

backupascopyreuse

archiveloglike"/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_03_08/o1_mf_1_7_6qb3zyoo_.arc"auxiliaryformat

"/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf";

catalogclonearchivelog"/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf";

switchclonedatafileall;

}

executingMemoryScript

Startingbackupat08-MAR-11

usingchannelORA_DISK_1

channelORA_DISK_1:startingarchivedlogcopy

inputarchivedlogthread=1sequence=7RECID=3STAMP=745203841

outputfilename=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbfRECID=0STAMP=0

channelORA_DISK_1:archivedlogcopycomplete,elapsedtime:00:00:07

Finishedbackupat08-MAR-11

catalogedarchivedlog

archivedlogfilename=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbfRECID=3STAMP=745203848

datafile1switchedtodatafilecopy

inputdatafilecopyRECID=3STAMP=745203849filename=/u01/app/oracle/oradata/orcl/system01.dbf

datafile2switchedtodatafilecopy

inputdatafilecopyRECID=4STAMP=745203849filename=/u01/app/oracle/oradata/orcl/sysaux01.dbf

datafile3switchedtodatafilecopy

inputdatafilecopyRECID=5STAMP=745203849filename=/u01/app/oracle/oradata/orcl/undotbs01.dbf

datafile4switchedtodatafilecopy

inputdatafilecopyRECID=6STAMP=745203849filename=/u01/app/oracle/oradata/orcl/users01.dbf

contentsofMemoryScript:

{

setuntilscn844147;

recover

clonedatabase

deletearchivelog

;

}

executingMemoryScript

executingcommand:SETuntilclause

Startingrecoverat08-MAR-11

allocatedchannel:ORA_AUX_DISK_1

channelORA_AUX_DISK_1:SID=18devicetype=DISK

startingmediarecovery

archivedlogforthread1withsequence7isalreadyondiskasfile/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbf

archivedlogfilename=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_7_745174404.dbfthread=1sequence=7

mediarecoverycomplete,elapsedtime:00:00:01

Finishedrecoverat08-MAR-11

contentsofMemoryScript:

{

shutdowncloneimmediate;

startupclonenomount;

sqlclone"altersystemsetdb_name=

''ORCL''comment=

''ResettooriginalvaluebyRMAN''scope=spfile";

sqlclone"altersystemresetdb_unique_namescope=spfile";

shutdowncloneimmediate;

startupclonenomount;

}

executingMemoryScript

databasedismounted

Oracleinstanceshutdown

connectedtoauxiliarydatabase(notstarted)

Oracleinstancestarted

TotalSystemGlobalArea146472960bytes

FixedSize1335080bytes

VariableSize92274904bytes

DatabaseBuffers50331648bytes

RedoBuffers2531328bytes

sqlstatement:altersystemsetdb_name=''ORCL''comment=''ResettooriginalvaluebyRMAN''scope=spfile

sqlstatement:altersystemresetdb_unique_namescope=spfile

Oracleinstanceshutdown

connectedtoauxiliarydatabase(notstarted)

Oracleinstancestarted

TotalSystemGlobalArea146472960bytes

FixedSize1335080bytes

VariableSize92274904bytes

DatabaseBuffers50331648bytes

RedoBuffers2531328bytes

sqlstatement:CREATECONTROLFILEREUSESETDATABASE"ORCL"RESETLOGSARCHIVELOG

MAXLOGFILES16

MAXLOGMEMBERS3

MAXDATAFILES100

MAXINSTANCES8

MAXLOGHISTORY292

LOGFILE

GROUP1('/u01/app/oracle/oradata/orcl/redo01.log')SIZE50MREUSE,

GROUP2('/u01/app/oracle/oradata/orcl/redo02.log')SIZE50MREUSE,

GROUP3('/u01/app/oracle/oradata/orcl/redo03.log')SIZE50MREUSE

DATAFILE

'/u01/app/oracle/oradata/orcl/system01.dbf'

CHARACTERSETZHS16GBK

contentsofMemoryScript:

{

setnewnamefortempfile1to

"/u01/app/oracle/oradata/orcl/temp01.dbf";

switchclonetempfileall;

catalogclonedatafilecopy"/u01/app/oracle/oradata/orcl/sysaux01.dbf",

"/u01/app/oracle/oradata/orcl/undotbs01.dbf",

"/u01/app/oracle/oradata/orcl/users01.dbf";

switchclonedatafileall;

}

executingMemoryScript

executingcommand:SETNEWNAME

renamedtempfile1to/u01/app/oracle/oradata/orcl/temp01.dbfincontrolfile

catalogeddatafilecopy

datafilecopyfilename=/u01/app/oracle/oradata/orcl/sysaux01.dbfRECID=1STAMP=745203867

catalogeddatafilecopy

datafilecopyfilename=/u01/app/oracle/oradata/orcl/undotbs01.dbfRECID=2STAMP=745203867

catalogeddatafilecopy

datafilecopyfilename=/u01/app/oracle/oradata/orcl/users01.dbfRECID=3STAMP=745203867

datafile2switchedtodatafilecopy

inputdatafilecopyRECID=1STAMP=745203867filename=/u01/app/oracle/oradata/orcl/sysaux01.dbf

datafile3switchedtodatafilecopy

inputdatafilecopyRECID=2STAMP=745203867filename=/u01/app/oracle/oradata/orcl/undotbs01.dbf

datafile4switchedtodatafilecopy

inputdatafilecopyRECID=3STAMP=745203867filename=/u01/app/oracle/oradata/orcl/users01.dbf

contentsofMemoryScript:

{

Alterclonedatabaseopenresetlogs;

}

executingMemoryScript

databaseopened

FinishedDuplicateDbat08-MAR-11

RMAN>

复制结束。查询:

Target库:

SQL>selectname,dbidfromv$database;

NAMEDBID

-------------------

ORCL1272955137

Auxiliary库:

SQL>selectname,dbidfromv$database;

NAMEDBID

-------------------

ORCL1272984602

你可能感兴趣的:(oracle,数据库,database,target,Active)