Oracle 11gR2 使用 RMAN duplicate from active database 复制数据库
在Oracle10g下,我們可以使用RMANduplicate命令創(chuàng)建一個具有不同DBID的復(fù)制庫。到了Oracle11gR2,RMAN的duplicate有2種方法實現(xiàn):
1.Activedatabaseduplication
2.Backup-basedduplication
Activedatabaseduplication通過網(wǎng)絡(luò),直接copytarget庫到auxiliary庫,然后創(chuàng)建復(fù)制庫。這種方法就不需要先用RMAN備份數(shù)據(jù)庫,然后將備份文件發(fā)送到auxiliary端。
這個功能的作用是非常大的。尤其是對T級別的庫。因為對這樣的庫進行備份,然后將備份集發(fā)送到備庫,在進行duplicate的代價是非常大的。一備份要占用時間,二要占用備份空間,三在網(wǎng)絡(luò)傳送的時候,還需要占用帶寬和時間。所以Activedatabaseduplicate很好的解決了以上的問題。它對大庫的遷移非常有用。
如果是從RACduplicate到單實例,操作是一樣的。如果是從單實例duplicate到RAC。那么先duplicate到單實例。然后將單實例轉(zhuǎn)換成RAC。
下面我們看一下11gR2下,ActiveDatabaseDuplicate的步驟如下:
1.創(chuàng)建Auxiliary庫的InitializationParameter:
如果使用spfile,那么在pfile文件里只需要設(shè)置一個DB_NAME參數(shù),其他參數(shù)會在duplicate命令中自己設(shè)置。
如果使用pfile,那么需要設(shè)置如下參數(shù):
DB_NAME
CONTROL_FILES
DB_BLOCK_SIZE
DB_FILE_NAME_CONVERT
LOG_FILE_NAME_CONVERT
DB_RECOVERY_FILE_DEST
2.在Auxiliary庫創(chuàng)建PasswordFile文件
對于Backup-basedduplication,PasswordFile不是必須的,但是對于ActiveDatabaseDuplication,PasswordFile是必須的。因為ActiveDatabaseDuplication使用相同的SYSDBA密碼直接連接到auxiliary庫。所以,確保target和Auxiliary庫的SYSDBA密碼一樣很重要。
當(dāng)然,我們也可以在duplicate命令中加上PASSWORDFILE選項(也是默認值),這樣RMAN在copy的時候也會從target庫把密碼文件copy過來,如果auxiliary庫上已經(jīng)存在了Passwordfile,那么該操作會重寫那個文件。
如:
RMAN>DUPLICATETARGETDATABASETODave
2>FROMACTIVEDATABASE
3>NOFILENAMECHECK
4>PASSWORDFILE
5>SPFILE;
3.如果是windows平臺,還需要創(chuàng)建Databaseservice:
%setORACLE_SID=DAVE
%setORACLE_HOME=E:/oracle/product/11.1.0/db_1
%oradim-NEW-SIDDAVE
4.配置oraclenet,修改listener.ora和thetnsnames.ora文件:
在Target庫和Auxiliary都要修改。這個也可以使用netca和netmgr命令配置。
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.用第一步創(chuàng)建的pfile文件,將Auxiliary啟動到nomout狀態(tài)。然后進行ActiveDatabaseduplicate。
我們看一個完整的復(fù)制示例:
TargetDB:
IP:192.168.2.42
SID:orcl
Auxiliary:
IP:192.168.2.43
SID:orcl
我這里復(fù)制的目錄相同。如果不同的話需要在pfile里面加入db_file_name_convert和log_file_name_convert.
1.在Auxiliary創(chuàng)建pfile參數(shù)文件:
[oracle@qs-dmm-rh2dbs]$pwd
/u01/app/oracle/product/11.2.0/dbhome_1/dbs
[oracle@qs-dmm-rh2dbs]$catinitorcl.ora
DB_NAME=orcl
只有一個參數(shù):DB_NAME
2.在Auxiliary庫上創(chuàng)建口令文件
[oracle@qs-dmm-rh2admin]$orapwdfile=?/dbs/orapworclpassword=oracle
3.在Auxiliary庫創(chuàng)建相關(guān)的目錄結(jié)構(gòu):
[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.啟動Auxiliary到nomout狀態(tài):
[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.在Target和Auxiliary都配置OracleNet(Listener.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:
注意:如果target和Auxiliary庫的目錄結(jié)構(gòu)相同,記得加上nofilenamecheck參數(shù),不然會報如下錯誤:
RMAN-05001:auxiliaryfilename/u01/app/oracle/oradata/orcl/users01.dbfconflictswithafileusedbythetargetdatabase
如果目錄不同,在pfile里加如下2個參數(shù)進行轉(zhuǎn)換:
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數(shù)據(jù)文件,比較慢。
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>
復(fù)制結(jié)束。查詢:
Target庫:
SQL>selectname,dbidfromv$database;
NAMEDBID
-------------------
ORCL1272955137
Auxiliary庫:
SQL>selectname,dbidfromv$database;
NAMEDBID
-------------------
ORCL1272984602
轉(zhuǎn)載于:https://blog.51cto.com/ecloud/1323025
總結(jié)
以上是生活随笔為你收集整理的Oracle 11gR2 使用 RMAN duplicate from active database 复制数据库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 黑马程序员之《String 类练习》
- 下一篇: 如何申请一份iOS工作