关于RMAN复制的理论知识,参考我的Blog:
RMAN复制目标数据库的理论知识
http://blog.csdn.net/tianlesoftware/archive/2010/07/19/5746812.aspx
实验平台:redhat+oracle10g
源库的相关信息:
ORACLE_BASE:/u01/app/oracle
ORACLE_HOME:/u01/app/oracle/product/10.2.0/db_1
ORACLE_SID:ORCL
复制的数据库实例名假设为:DAVE
步骤如下:
(1)构建辅助数据库目录结构
(2)修改init.ora初始话文件
(3)创建辅助实例口令文件
(4)RMAN备份源库
(5)配置监听
(6)启动辅助库至nomount状态
(7)RMANduplicate复制实例
(8)创建spfile
一.构建辅助数据库目录结构
1.1Oracledata目录
[oracle@db1oradata]$ls
orcl
[oracle@db1oradata]$pwd
/u01/app/oracle/oradata
[oracle@db1oradata]$mkdirDAVE
[oracle@db1oradata]$ls
DAVEorcl
1.2其他目录
[oracle@db1admin]$pwd
/u01/app/oracle/admin
[oracle@db1admin]$mkdirDAVE
[oracle@db1admin]$ls
DAVEorcl
[oracle@db1admin]$cdorcl
[oracle@db1orcl]$ls
adumpbdumpcdumpdpdumppfileudump
[oracle@db1DAVE]$cd..
[oracle@db1admin]$cdDAVE
[oracle@db1DAVE]$mkdirbdump
[oracle@db1DAVE]$mkdircdump
[oracle@db1DAVE]$mkdirpfile
[oracle@db1DAVE]$mkdirudump
[oracle@db1DAVE]$ls
adumpbdumpcdumpdpdumppfileudump
二.修改init.ora初始化文件
2.1生成源库的pfile文件,默认生成位置在$ORACLE_HOME/dbs目录下:
SQL>conn/assysdba
Connected.
SQL>createpfilefromspfile;
Filecreated.
2.2进入$ORACLE_HOME/dbs目录,将init文件copy并重命名为initDAVE.ora.这个命名格式必须和实例名相同,不然数据库不能识别。
[oracle@db1DAVE]$cd$ORACLE_HOME/dbs
[oracle@db1dbs]$ls
hc_orcl.datinit.oralkORCLsnapcf_orcl.f
initdw.orainitorcl.oraorapworclspfileorcl.ora
[oracle@db1dbs]$cpinitorcl.orainitDAVE.ora
[oracle@db1dbs]$ls
hc_orcl.datinitdw.orainitorcl.oraorapworclspfileorcl.ora
initDAVE.orainit.oralkORCLsnapcf_orcl.f
2.3修改initDAVE.ora文件,将orcl改成DAVE
[oracle@db1dbs]$moreinitDAVE.ora
orcl.__db_cache_size=171966464
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__shared_pool_size=58720256
orcl.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/DAVE/adump'
*.background_dump_dest='/u01/app/oracle/admin/DAVE/bdump'
*.compatible='10.2.0.1.0'
*.control_file_record_keep_time=14
*.control_files='/u01/app/oracle/oradata/DAVE/control01.ctl','/u01/app/oracle/oradata/DAVE/control02.ctl'
,'/u01/app/oracle/oradata/DAVE/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/DAVE/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='DAVE'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP)(SERVICE=orclXDB)'
*.job_queue_processes=10
*.log_archive_dest_1='location=/u01/archivelog'
*.open_cursors=300
*.pga_aggregate_target=81788928
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=246415360
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/DAVE/udump'
db_file_name_convert=('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')
log_file_name_convert=('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')
其中红色部分就是修改的部分.Db_file_name_convert和log_file_name_convert两个参数是我们添加的,用来转换数据文件位置和redolog位置。在复制完成后,可以删除这2个参数。
三.创建DAVE实例的口令文件
[oracle@db1dbs]$cd$ORACLE_HOME/bin
[oracle@db1bin]$orapwdfile=$ORACLE_HOME/dbs/orapwDAVEpassword=admin
[oracle@db1bin]$cd$ORACLE_HOME/dbs
[oracle@db1dbs]$ls
hc_orcl.datinitdw.orainitorcl.oraorapwDAVEsnapcf_orcl.f
initDAVE.orainit.oralkORCLorapworclspfileorcl.ora
windows下oracle默认的位置是$ORACLE_HOME/database目录,文件名格式是pwdSID.ora。
linux下oracle默认的位置是$ORACLE_HOME/dbs目录,文件名格式是orapwSID。
创建完后,数据库需要重启动,新的口令文件才能生效。
关于口令文件创建,详细内容参考blog:
OracleOS认证口令文件密码丢失处理
http://blog.csdn.net/tianlesoftware/archive/2009/10/20/4698293.aspx
四.RMAN备份源库(orcl)
[oracle@db1u02]$rmantarget/
RecoveryManager:Release10.2.0.1.0-ProductiononSunJul1810:57:532010
Copyright(c)1982,2005,Oracle.Allrightsreserved.
connectedtotargetdatabase:ORCL(DBID=1248423599)
RMAN>RUN{
allocatechannelc1typedisk;
allocatechannelc2typedisk;
BACKUPFORMAT'/u02/backup/orcl_%U_%T'skipinaccessiblefilesperset5DATABASETAGorcl_hot_db_bk;
sql'altersystemarchivelogcurrent';
BACKUPFORMAT'/u02/backup/arch_%U_%T'skipinaccessiblefilesperset5ARCHIVELOGALLDELETEINPUT;
backupcurrentcontrolfiletag='bak_ctlfile'format='/u02/backup/ctl_file_%U_%T';
backupspfiletag='spfile'format='/u02/backup/ORCL_spfile_%U_%T';
releasechannelc2;
releasechannelc1;
}
备份脚本,具体参考:
Linux平台下RMAN全备和增量备份shell脚本
http://blog.csdn.net/tianlesoftware/archive/2010/07/16/5740630.aspx
五.添加,配置监听
5.1修改listener.ora文件,添加如下内容
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=PLSExtProc)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
(PROGRAM=extproc)
)
(SID_DESC=
(GLOBAL_DBNAME=DAVE)
(ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
(SID_NAME=DAVE)
)
)
5.2修改tnsnames.ora文件,添加如下内容
DAVE=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=TCP)(HOST=db1)(PORT=1521))
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=DAVE)
)
)
建议使用netmanager工具从界面来修改,这样不容易出错
Oracle数据库监听配置
http://blog.csdn.net/tianlesoftware/archive/2009/11/25/4861572.aspx
OracleListener动态注册与静态注册
http://blog.csdn.net/tianlesoftware/archive/2010/04/30/5543166.aspx
六.启动辅助库到nomount状态
[oracle@db1admin]$exportORACLE_SID=DAVE
[oracle@db1admin]$sqlplus/nolog
SQL*Plus:Release10.2.0.1.0-ProductiononSunJul1811:17:012010
Copyright(c)1982,2005,Oracle.Allrightsreserved.
SQL>conn/assysdba
Connectedtoanidleinstance.
SQL>startupnomountpfile=?/dbs/initDAVE.ora--注意要指定pfile
ORACLEinstancestarted.
TotalSystemGlobalArea247463936bytes
FixedSize1218748bytes
VariableSize79693636bytes
DatabaseBuffers159383552bytes
RedoBuffers7168000bytes
SQL>
七.RMAN连接到目标实例和辅助实例,运行duplicate命令复制数据库
[oracle@db1u02]$exportORACLE_SID=orcl
[oracle@db1u02]$rmantarget/
RecoveryManager:Release10.2.0.1.0-ProductiononSunJul1811:41:012010
Copyright(c)1982,2005,Oracle.Allrightsreserved.
connectedtotargetdatabase:ORCL(DBID=1248423599)
RMAN>connectauxiliarysys/admin@DAVE;
connectedtoauxiliarydatabase:DAVE(notmounted)
RMAN>duplicatetargetdatabasetoDAVE;
StartingDuplicateDbat18-JUL-10
usingtargetdatabasecontrolfileinsteadofrecoverycatalog--用的是原来的控制文件
allocatedchannel:ORA_AUX_DISK_1
channelORA_AUX_DISK_1:sid=155devtype=DISK
contentsofMemoryScript:
{
setuntilscn697286;
setnewnamefordatafile1to"/u01/app/oracle/oradata/DAVE/system01.dbf";--转换文件位置
setnewnamefordatafile2to"/u01/app/oracle/oradata/DAVE/undotbs01.dbf";
setnewnamefordatafile3to"/u01/app/oracle/oradata/DAVE/sysaux01.dbf";
setnewnamefordatafile4to"/u01/app/oracle/oradata/DAVE/users01.dbf";
setnewnamefordatafile5to"/u01/app/oracle/oradata/DAVE/example01.dbf";
restore
checkreadonly
clonedatabase;
}
executingMemoryScript
executingcommand:SETuntilclause
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
executingcommand:SETNEWNAME
Startingrestoreat18-JUL-10
usingchannelORA_AUX_DISK_1
channelORA_AUX_DISK_1:startingdatafilebackupsetrestore--开始restore数据文件
channelORA_AUX_DISK_1:specifyingdatafile(s)torestorefrombackupset
restoringdatafile00002to/u01/app/oracle/oradata/DAVE/undotbs01.dbf
restoringdatafile00003to/u01/app/oracle/oradata/DAVE/sysaux01.dbf
restoringdatafile00005to/u01/app/oracle/oradata/DAVE/example01.dbf
channelORA_AUX_DISK_1:readingfrombackuppiece/u02/backup/orcl_39lj3bmt_1_1_20100718
channelORA_AUX_DISK_1:restoredbackuppiece1
piecehandle=/u02/backup/orcl_39lj3bmt_1_1_20100718tag=ORCL_HOT_DB_BK
channelORA_AUX_DISK_1:restorecomplete,elapsedtime:00:00:47
channelORA_AUX_DISK_1:startingdatafilebackupsetrestore
channelORA_AUX_DISK_1:specifyingdatafile(s)torestorefrombackupset
restoringdatafile00001to/u01/app/oracle/oradata/DAVE/system01.dbf
restoringdatafile00004to/u01/app/oracle/oradata/DAVE/users01.dbf
channelORA_AUX_DISK_1:readingfrombackuppiece/u02/backup/orcl_38lj3bmt_1_1_20100718
channelORA_AUX_DISK_1:restoredbackuppiece1
piecehandle=/u02/backup/orcl_38lj3bmt_1_1_20100718tag=ORCL_HOT_DB_BK
channelORA_AUX_DISK_1:restorecomplete,elapsedtime:00:00:45
Finishedrestoreat18-JUL-10
sqlstatement:CREATECONTROLFILEREUSESETDATABASE"DAVE"RESETLOGSARCHIVELOG
--创建源库的控制文件,然后用这个控制文件进行恢复
MAXLOGFILES16
MAXLOGMEMBERS3
MAXDATAFILES100
MAXINSTANCES8
MAXLOGHISTORY292
LOGFILE
GROUP1('/u01/app/oracle/oradata/DAVE/redo01.log')SIZE50MREUSE,
GROUP2('/u01/app/oracle/oradata/DAVE/redo02.log')SIZE50MREUSE,
GROUP3('/u01/app/oracle/oradata/DAVE/redo03.log')SIZE50MREUSE
DATAFILE
'/u01/app/oracle/oradata/DAVE/system01.dbf'
CHARACTERSETWE8ISO8859P1
contentsofMemoryScript:
{
switchclonedatafileall;
}
executingMemoryScript
releasedchannel:ORA_AUX_DISK_1
datafile2switchedtodatafilecopy
inputdatafilecopyrecid=1stamp=724679047filename=/u01/app/oracle/oradata/DAVE/undotbs01.dbf
datafile3switchedtodatafilecopy
inputdatafilecopyrecid=2stamp=724679047filename=/u01/app/oracle/oradata/DAVE/sysaux01.dbf
datafile4switchedtodatafilecopy
inputdatafilecopyrecid=3stamp=724679047filename=/u01/app/oracle/oradata/DAVE/users01.dbf
datafile5switchedtodatafilecopy
inputdatafilecopyrecid=4stamp=724679047filename=/u01/app/oracle/oradata/DAVE/example01.dbf
contentsofMemoryScript:
{
setuntilscn697286;
recover
clonedatabase
deletearchivelog
;
}
executingMemoryScript
executingcommand:SETuntilclause
Startingrecoverat18-JUL-10--开始recover恢复数据
allocatedchannel:ORA_AUX_DISK_1
channelORA_AUX_DISK_1:sid=155devtype=DISK
startingmediarecovery
channelORA_AUX_DISK_1:startingarchivelogrestoretodefaultdestination
--先将归档日志还原到指定的归档目录:log_archive_dest参数指定
channelORA_AUX_DISK_1:restoringarchivelog
archivelogthread=1sequence=41
channelORA_AUX_DISK_1:readingfrombackuppiece/u02/backup/arch_3dlj3bro_1_1_20100718
channelORA_AUX_DISK_1:restoredbackuppiece1
piecehandle=/u02/backup/arch_3dlj3bro_1_1_20100718tag=TAG20100718T110111
channelORA_AUX_DISK_1:restorecomplete,elapsedtime:00:00:02
channelORA_AUX_DISK_1:startingarchivelogrestoretodefaultdestination
channelORA_AUX_DISK_1:restoringarchivelog
archivelogthread=1sequence=40
channelORA_AUX_DISK_1:readingfrombackuppiece/u02/backup/arch_3clj3bro_1_1_20100718
channelORA_AUX_DISK_1:restoredbackuppiece1
piecehandle=/u02/backup/arch_3clj3bro_1_1_20100718tag=TAG20100718T110111
channelORA_AUX_DISK_1:restorecomplete,elapsedtime:00:00:01
archivelogfilename=/u01/archivelog/1_40_720642866.dbfthread=1sequence=40
channelclone_default:deletingarchivelog(s)
archivelogfilename=/u01/archivelog/1_40_720642866.dbfrecid=2stamp=724679053
archivelogfilename=/u01/archivelog/1_41_720642866.dbfthread=1sequence=41
channelclone_default:deletingarchivelog(s)
archivelogfilename=/u01/archivelog/1_41_720642866.dbfrecid=1stamp=724679052
mediarecoverycomplete,elapsedtime:00:00:04
Finishedrecoverat18-JUL-10
contentsofMemoryScript:
{
shutdownclone;
startupclonenomount;
--这里要注意的一个地方,在这一步的时候,辅助实例不能有任何session打开,即不能有有任何连接连接到DAVE上,不然它会一直那个session退出后才能执行
}
executingMemoryScript
databasedismounted
Oracleinstanceshutdown
connectedtoauxiliarydatabase(notstarted)
Oracleinstancestarted
TotalSystemGlobalArea247463936bytes
FixedSize1218748bytes
VariableSize79693636bytes
DatabaseBuffers159383552bytes
RedoBuffers7168000bytes
sqlstatement:CREATECONTROLFILEREUSESETDATABASE"DAVE"RESETLOGSARCHIVELOG
--复制已经完成,创建新的控制文件(DAVE的控制文件),可以参考理论知识的连接
MAXLOGFILES16
MAXLOGMEMBERS3
MAXDATAFILES100
MAXINSTANCES8
MAXLOGHISTORY292
LOGFILE
GROUP1('/u01/app/oracle/oradata/DAVE/redo01.log')SIZE50MREUSE,
GROUP2('/u01/app/oracle/oradata/DAVE/redo02.log')SIZE50MREUSE,
GROUP3('/u01/app/oracle/oradata/DAVE/redo03.log')SIZE50MREUSE
DATAFILE
'/u01/app/oracle/oradata/DAVE/system01.dbf'
CHARACTERSETWE8ISO8859P1
contentsofMemoryScript:
{
setnewnamefortempfile1to"/u01/app/oracle/oradata/DAVE/temp01.dbf";
switchclonetempfileall;
catalogclonedatafilecopy"/u01/app/oracle/oradata/DAVE/undotbs01.dbf";
catalogclonedatafilecopy"/u01/app/oracle/oradata/DAVE/sysaux01.dbf";
catalogclonedatafilecopy"/u01/app/oracle/oradata/DAVE/users01.dbf";
catalogclonedatafilecopy"/u01/app/oracle/oradata/DAVE/example01.dbf";
switchclonedatafileall;
}
executingMemoryScript
executingcommand:SETNEWNAME
renamedtemporaryfile1to/u01/app/oracle/oradata/DAVE/temp01.dbfincontrolfile
catalogeddatafilecopydatafilecopyfilename=/u01/app/oracle/oradata/DAVE/undotbs01.dbfrecid=1stamp=724679599
catalogeddatafilecopydatafilecopyfilename=/u01/app/oracle/oradata/DAVE/sysaux01.dbfrecid=2stamp=724679599
catalogeddatafilecopydatafilecopyfilename=/u01/app/oracle/oradata/DAVE/users01.dbfrecid=3stamp=724679599
catalogeddatafilecopydatafilecopyfilename=/u01/app/oracle/oradata/DAVE/example01.dbfrecid=4stamp=724679599
datafile2switchedtodatafilecopy
inputdatafilecopyrecid=1stamp=724679599filename=/u01/app/oracle/oradata/DAVE/undotbs01.dbf
datafile3switchedtodatafilecopy
inputdatafilecopyrecid=2stamp=724679599filename=/u01/app/oracle/oradata/DAVE/sysaux01.dbf
datafile4switchedtodatafilecopy
inputdatafilecopyrecid=3stamp=724679599filename=/u01/app/oracle/oradata/DAVE/users01.dbf
datafile5switchedtodatafilecopy
inputdatafilecopyrecid=4stamp=724679599filename=/u01/app/oracle/oradata/DAVE/example01.dbf
contentsofMemoryScript:
{
Alterclonedatabaseopenresetlogs;
}
executingMemoryScript
databaseopened
FinishedDuplicateDbat18-JUL-10
八.修改辅助库的pfile,在创建spfile
8.1删除下面2句:
db_file_name_convert=('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')
log_file_name_convert=('/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/DAVE')
8.2创建spfile
[oracle@db1dbs]$sqlplus/nolog
SQL*Plus:Release10.2.0.1.0-ProductiononSunJul1812:11:282010
Copyright(c)1982,2005,Oracle.Allrightsreserved.
SQL>connsys/admin@DAVEassysdba;
Connected.
SQL>createspfilefrompfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initDAVE.ora';
Filecreated.
九.如果使用磁带备份
完成了上面的8步,RMAN的同机复制就已经完成了。如果要在相同的服务器上复制磁带备份,只需要在最后运行duplicate命令前插入一个额外的步骤即可。该步骤配置辅助通道,使之与执行备份的通道类型。
9.1先在源库上执行showchannel命令,查看通道信息
9.2然后在创建相应的configure命令来匹配辅助的通道
------------------------------------------------------------------------------
Blog:http://blog.csdn.net/tianlesoftware
网上资源:http://tianlesoftware.download.csdn.net
相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx
DBA1群:62697716(满);DBA2群:62697977
DBA3群:63306533;聊天群:40132017