|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
人力成本上的节省,MySQL的用户Spacemonkey实验室的首席执行官MitchPirtle如此表示:“维护MySQL使得你不需要一个年薪15万美元的DBA。oracle|备份|恢复
一.了解甚么是数据库恢复
当我们利用一个数据库时,总但愿数据库的内容是牢靠的、准确的,但因为盘算机体系的妨碍(硬件妨碍、软件妨碍、收集妨碍、历程妨碍和体系妨碍)影响数据库体系的操纵,影响数据库中数据的准确性,乃至损坏数据库,使数据库中全体或部分数据丧失。因而当产生上述妨碍后,但愿能重构这个完全的数据库,该处置称为数据库恢复。恢复历程大抵能够分为回复(Restore)与恢复(Recover)历程。
数据库恢复能够分为以下两类:
1.1实例妨碍的分歧性恢复
当实例不测地(如失落电、背景历程妨碍等)或意料地(收回SHUTDOUMABORT语句)中断时呈现实例妨碍,此时必要实例恢复。实例恢复将数据库恢复到妨碍之前的事件分歧形态。假如在在线后备发明实例妨碍,则需介质恢复。在别的情形Oracle鄙人次数据库起动时(对新实例拆卸和翻开),主动地实行实例恢复。假如必要,从拆卸形态变成翻开形态,主动地引发实例恢复,由以下处置:
(1)为懂得恢单数据文件中没有纪录的数据,举行向前滚。该数据纪录在在线日记,
包含对回滚段的内容恢复。
(2)回滚未提交的事件,按步1从头天生回滚段所指定的操纵。
(3)开释在妨碍时正在处置事件所持有的资本。
(4)办理在妨碍时正派历一阶段提交的任何悬而未决的散布事件。
1.2介质妨碍或文件毛病的纷歧致恢复
介质妨碍是当一个文件、一个文件的部分或磁盘不克不及读或不克不及写时呈现的妨碍。文件毛病一样平常指不测的毛病招致文件被删除或不测变乱招致文件的纷歧致。这类形态下的数据库都是纷歧致的,必要DBA手工来举行数据库的恢复,这类恢复有两种情势,决意于数据库运转的回档体例和备份体例。
(1)完整介质恢复可恢复全体丧失的修正。一样平常情形下必要无数据库的备份且数据库运转在回档形态下而且有可用回档日记时才大概。关于分歧范例的毛病,有分歧范例的完整恢复可以使用,其决意于损坏文件和数据库的可用性。
(2)不完整介质恢复是在完整介质恢复不成能或不请求时举行的介质恢复。重构受损的数据库,使其恢复介质妨碍前或用户堕落之前的一个事件分歧性形态。不完整介质恢复有分歧范例的利用,决意于必要不完整介质恢复的情形,有以下范例:基于取消、基于工夫和基于修正的不完整恢复。
基于取消(CANCEL)恢复:在某种情形,不完整介质恢复必需被把持,DBA可取消在指定点的操纵。基于取消的恢复地在一个或多个日记组(在线的或回档的)已被介质妨碍所损坏,不克不及用于恢复历程时利用,以是介质恢复必需把持,乃至在利用比来的、未损的日记组于数据文件后中断恢复操纵。
基于工夫(TIME)和基于修正(SCN)的恢复:假如DBA但愿恢复到已往的某个指定点,是一种幻想的不完整介质恢复,一样平常产生在恢复到某个特定操纵之前,恢复到快意外删除某个数据表之前。
第二章.数据库恢复案例测试情况
2.1数据库情况
以下的一切案例都是经由过程测试经由,情况为:
OS:Windows2000Server
DB:Oracle816
DBNAME:TEST
数据文件:
SQL>selectfile#,status,enabled,namefromv$datafile;
FILE#STATUSENABLEDNAME
----------------------------------------------------------------
1SYSTEMREADWRITED:OracleORADATATESTYSTEM01.DBF
2ONLINEREADWRITED:OracleORADATATESTRBS01.DBF
3ONLINEREADWRITED:OracleORADATATESTUSERS01.DBF
4ONLINEREADWRITED:OracleORADATATESTTEMP01.DBF
5ONLINEREADWRITED:OracleORADATATESTTOOLS01.DBF
6ONLINEREADWRITED:OracleORADATATESTINDX01.DBF
把持文件:
SQL>select*fromv$controlfile;
STATUSNAME
---------------------------------------------------------------------
D:OracleORADATATESTCONTROL01.CTL
D:OracleORADATATESTCONTROL02.CTL
D:OracleORADATATESTCONTROL03.CTL
联机日记:
SQL>select*fromv$logfile;
GROUP#STATUSMEMBER
---------------------------------------------------------------------
1STALED:OracleORADATATESTREDO01.LOG
2D:OracleORADATATESTREDO02.LOG
3STALED:OracleORADATATESTREDO03.LOG
2.2数据库备份剧本
冷备份剧本:
remscript:coldbak.sql
remcreater:chenjiping
remdate:5.8.2003
remdesc:offlinefullbackupdatabase
--connectdatabase
connectinternal/password;
--shutdowndatabase
shutdownimmediate;
--CopyDatafile
!xcopyd:Oracleoradata est*.dbfd:database/H/R;
--CopyControlfile
!xcopyd:Oracleoradata est*.ctld:database/H/R;
--CopyLogfile
!xcopyd:Oracleoradata est*.logd:database/H/R;
--startupdatabase
startup;
申明:
1、以上剧本在数据库封闭形态下备份数据库一切的数据文件,联机日记,把持文件(在一个目
录下),假如乐成备份,一切文件是分歧的;
2、没有备份参数文件,参数文件能够别的备份,没有需要每次都备份,只必要在改动设置后备份一次;
3、假如以上命令没有乐成顺次实行,那末备份将是有效的,如毗连数据库不乐成,那末一定封闭数据库也不乐成,那末备份则有效;
4、冷备份倡议下野生干涉下实行。
数据库OS热全备份剧本
remscript:hotbak.sql
remcreater:chenjiping
remdate:5.8.2003
remdesc:backupalldatabasedatafileinarchive
--connectdatabase
connectinternal/password;
--archive
altersystemarchivelogcurrent;
--start
altertablespacesystembeginbackup;
!xcopyd:Oracleoradata estystem01.dbfd:databak/H/R;
altertablespacesystemendbackup;
altertablespacerbsbeginbackup;
!xcopyd:Oracleoradata estbs01.dbfd:databak/H/R;
altertablespacerbsendbackup;
altertablespaceusersbeginbackup;
!xcopyd:Oracleoradata estusers01.dbfd:databak/H/R;
altertablespaceusersendbackup;
altertablespacetoolsbeginbackup;
!xcopyd:Oracleoradata est ools01.dbfd:databak/H/R;
altertablespacetoolsendbackup;
altertablespaceindxbeginbackup;
!xcopyd:Oracleoradata estindx01.dbfd:databak/H/R;
altertablespaceindxendbackup;
--end
--bakcontrolfile
--binary
alterdatabasebackupcontrolfiletod:databakcontrolbinbak.000;
--ascii
alterdatabasebackupcontrolfiletotrace;
altersystemarchivelogcurrent;
申明:
1、热备份必需在数据库回档体例下才能够运转;
2、以上剧本能够在数据库运转形态下备份数据库一切的数据文件(除一时数据文件),没有需要备份联机日记;
3、回档日记最少必要一次完全备份以后的一切日记;
4、假如以上命令没有乐成顺次实行,那末备份也是有效的,如毗连数据库不乐成,那末备份则有效。
RMAN备份只讲叙有恢复目次的情形,假如没有恢复目次,情况大抵类似。以下是RMAN的热备份全备份的剧本:
#script:bakup.rcv
#creater:chenjiping
#date:5.8.2003
#desc:backupalldatabasedatafileinarchivewithrman
#connectdatabase
connectrcvcatrman/rman@back;
connecttargetinternal/virpure;
#startbackupdatabase
run{
allocatechannelc1typedisk;
backupfulltagdbfullformatd:ackupfull%u_%s_%pdatabase
includecurrentcontrolfile;
sqlaltersystemarchivelogcurrent;
releasechannelc1;
}
#end
申明:
1、数据库必需运转在回档形式下;
2、RMAN将主动备份数据文件,运转牢靠;
3、回档日记别的备份处置,但最少必要保留一次备份来的日记;
4、没有需要用RMAN做冷备份,效果欠好。
以上举例申明了数据库的恢复案例的测试情况与部分备份测试剧本,别的的备份剧本能够依据以上剧本演化而来或在案例中加以申明。
数据库的主动实例将不加以申明,这里只举例申明媒体毛病某人为毛病酿成的恢复大概。
以上包含以下案例都是在WINDOWS+Oracle816上测实验证的,在分歧的操纵体系与分歧的数据库版本中略有不同。
第三章.懂得与恢复相干的信息
1、了解报警日记文件
报警日记文件一样平常纪录了数据库的启动/封闭信息,回档信息,备份信息,恢覆信息,罕见毛病信息,部分数据库修正纪录等。一样平常令名划定规矩为<SID>Alrt.log或Alrt<SID>.log,如我的测试数据库的报警日记文件的称号为testalrt.log。
报警日记文件的路径是依据初始化参数background_dump_dest来决意的,如在我的呆板上,该参数值为D:Oracleadmin estdump,那末,你就能够在该路径下找到该文件。
2、背景历程跟踪文件
背景历程跟踪文件的路径与报警日记文件的路径分歧,在某些情形下,你能够经由过程背景跟踪文件的信息懂得更多的必要恢复的信息。如在数据库必要恢复的时分,报警日记文件中常有如许的语句:
ErrorsinfileD:Oracleadmin estdump estDBW0.TRC:
ORA-01157:cannotidentify/lockdatafile1-seeDBWRtracefile
经由过程提醒的DBWR跟踪文件,能够查询到更具体的信息。
3、v$recover_file与v$recovery_log
这是两个静态功能视图,能够在mount下检察,经由过程这两个视图,你能够懂得具体的必要恢复的数据文件与必要利用到的回档日记。
第四章.数据库恢复案例
4.1非回档形式下的备份与恢复
备份计划:接纳OS冷备份
1.毗连数据库并创立测试表
SQL>connectinternal/passwordassysdba;
Connected.
SQL>createtabletest(aint);
Tablecreated
SQL>insertintotestvalues(1);
1rowinserted
SQL>commit;
Commitcomplete
2.备份数据库
SQL>@coldbak.sql或在DOS下svrmgrl@coldbak.sql
3.再拔出纪录
SQL>insertintotestvalues(2);
1rowinserted
SQL>commit;
Commitcomplete
SQL>select*fromtest;
A
-------------------
1
2
4.封闭数据库
SQL>shutdownimmediate;
Databaseclosed.
Databasedismounted.
Oracleinstanceshutdown.
5.损坏一个或多个数据文件,如删除user01.dbf
C:>delD:OracleORADATATESTUSERS01.DBF
摹拟媒体损坏。
6.从头启动数据库,会发明以下毛病
SQL>startup
Oracleinstancestarted.
TotalSystemGlobalArea102020364bytes
FixedSize70924bytes
VariableSize85487616bytes
DatabaseBuffers16384000bytes
RedoBuffers77824bytes
Databasemounted.
ORA-01157:cannotidentify/lockdatafile3-seeDBWRtracefile
ORA-01110:datafile3:D:OracleORADATATESTUSERS01.DBF
在报警文件中,会有更具体的信息
ErrorsinfileD:Oracleadmin estdump estDBW0.TRC:
ORA-01157:cannotidentify/lockdatafile3-seeDBWRtracefile
ORA-01110:datafile3:D:OracleORADATATESTUSERS01.DBF
ORA-27041:unabletoopenfile
OSD-04002:unabletoopenfile
O/S-Error:(OS2)体系找不到指定的文件。
7.拷贝备份回复到本来地位(restore历程)
C:>xcopyd:database*.*d:Oracleoradata est/H/R/S
8.翻开数据库,反省数据
SQL>alterdatabaseopen;
Databasealtered.
SQL>select*fromtest;
A
---------------------------------------
1
这里能够发明,数据库恢复乐成,但在备份以后与溃散之前的数据丧失了。
申明:
1、非回档形式下的恢复计划可选性很小,一样平常情形下只能有一种恢复体例,就是数据库的冷备
份的完整恢复,仅仅必要拷贝本来的备份就能够(restore),不必要recover;
2、这类情形下的恢复,能够完整恢复到备份的点上,可是多是丧失数据的,在备份以后与溃散之前的数据将全体丧失;
3、不论损坏了几数据文件或是联机日记或是把持文件,都能够经由过程这个举措恢复,由于这个恢复历程是Restore一切的冷备份文件,而这个备份点上的一切文件是分歧的,与最新的数据库没有干系,就比如把数据库又放到了一个之前的"点"上;
4、关于非回档形式下,最好的举措就是接纳OS的冷备份,倡议不要用RMAN来作冷备份,效果欠好,由于RMAN不备份联机日记,restore不克不及基本办理成绩;
5、假如没有备份联机日记,如RMAN的备份,就必要使用不完整恢复(untilcancel)的办法来从头创立联机日记文件。
4.2回档形式下丧失或破坏一个数据文件
4.2.1OS备份计划
在回档体例下破坏或丧失一个数据文件,假如存在响应的备份与该备份以来的回档日记,恢复仍是对照复杂的,能够作到只管少的Down机工夫,并能作到数据库的完整恢复。
1、毗连数据库,创立测试表并拔出纪录
SQL>connectinternal/passwordassysdba;
Connected.
SQL>createtabletest(aint)tablespaceusers;
Tablecreated
SQL>insertintotestvalues(1);
1rowinserted
SQL>commit;
Commitcomplete
2、备份数据库
SQL>@hotbak.sql或在DOS下svrmgrl@hotbak.sql
3、持续在测试表中拔出纪录
SQL>insertintotestvalues(2);
1rowinserted
SQL>commit;
Commitcomplete
SQL>select*fromtest;
A
--------------------------------------
1
2
SQL>altersystemswitchlogfile;
Systemaltered.
SQL>altersystemswitchlogfile;
Systemaltered.
4、封闭数据库,摹拟丧失数据文件
SQL>shutdownimmediate;
Databaseclosed.
Databasedismounted.
Oracleinstanceshutdown
C:>delD:OracleORADATATESTUSERS01.DBF
摹拟媒体损坏。
5、启动数据库毛病,脱机该数据文件:
SQL>startup
Oracleinstancestarted.
TotalSystemGlobalArea102020364bytes
FixedSize70924bytes
VariableSize85487616bytes
DatabaseBuffers16384000bytes
RedoBuffers77824bytes
Databasemounted.
ORA-01157:cannotidentify/lockdatafile3-seeDBWRtracefile
ORA-01110:datafile3:D:OracleORADATATESTUSERS01.DBF
还能够检察报警文件(见上一个恢复案例)或静态视图v$recover_file
如SQL>select*fromv$recover_file;
FILE#ONLINEERRORCHANGE#TIME
--------------------------------------------------------
3ONLINE10135002003-05-07
脱机数据文件
SQL>alterdatabasedatafile3offlinedrop;
Databasealtered.
6、翻开数据库,拷贝备份返来(restore),恢复(recover)该数据文件,并联机:
SQL>alterdatabaseopen;
Databasealtered.
拷贝备份从备份处
copyd:databakusers01.dbfd:Oracleoradata est;
恢复该数据文件
SQL>recoverdatafile3;
ORA-00279:change1053698generatedat05/07/200317:51:26neededfor
thread1
ORA-00289:suggestion:
D:OracleORADATATESTARCHIVETESTT001S00304.ARC
ORA-00280:change1053698forthread1isinsequence#304
Specifylog:{<RET>=suggested|filename|AUTO|CANCEL}
AUTO
ORA-00279:change1053701generatedat05/07/200317:51:39neededfor
thread1
ORA-00289:suggestion:D:OracleORADATATESTARCHIVETESTT001S00305.ARC
ORA-00280:change1053701forthread1isinsequence#305
ORA-00278:logfileD:OracleORADATATESTARCHIVETESTT001S00304.ARCnolongerneededforthisrecoveryLogapplied.
Mediarecoverycomplete.
恢复乐成,联机该数据文件
SQL>alterdatabasedatafile3online;
Databasealtered.
7、反省数据库的数据(完整恢复)
SQL>select*fromtest;
A
--------------------------------
1
2
申明:
1、接纳热备份,必要运转在回档形式下,能够完成数据库的完整恢复,也就是说,从备份后到数据库溃散时的数据都不会丧失;
2、能够接纳全备份数据库的体例备份,关于特别情形,也能够只备份特定的数据文件,如只备份用户表空间(一样平常情形下关于某些写出格频仍的数据文件,能够独自加年夜备份频次);
3、假如在恢复过程当中,发明破坏的是多个数据文件,便可以接纳一个一个数据文件的恢复办法(第5步中必要对数据文件逐一脱机,第6步中必要对数据文件分离恢复),也能够接纳全部数据库的恢复办法;
4、假如是体系表空间的破坏,不克不及接纳此办法。
4.2.2RMAN备份计划
RMAN也能够举行联机备份,并且备份与恢复办法将比OS备份更复杂牢靠。
1、毗连数据库,创立测试表并拔出纪录
SQL>connectinternal/passwordassysdba;
Connected.
SQL>createtabletest(aint)tablespaceusers;
Tablecreated
SQL>insertintotestvalues(1);
1rowinserted
SQL>commit;
Commitcomplete
2、备份数据库表空间users
C:>rman
RecoveryManager:Release8.1.6.0.0-Production
RMAN>connectrcvcatrman/rman@back
RMAN-06008:connectedtorecoverycatalogdatabase
RMAN>connecttargetinternal/virpure
RMAN-06005:connectedtotargetdatabase:TEST(DBID=1788174720)
RMAN>run{
2>allocatechannelc1typedisk;
3>backuptagtsuserformatd:ackup suser_%u_%s_%p
4>tablespaceusers;
5>releasechannelc1;
6>}
RMAN-03022:compilingcommand:allocate
RMAN-03023:executingcommand:allocate
RMAN-08030:allocatedchannel:c1
RMAN-08500:channelc1:sid=16devtype=DISK
RMAN-03022:compilingcommand:backup
RMAN-03025:performingimplicitpartialresyncofrecoverycatalog
RMAN-03023:executingcommand:partialresync
RMAN-08003:startingpartialresyncofrecoverycatalog
RMAN-08005:partialresynccomplete
RMAN-03023:executingcommand:backup
RMAN-08008:channelc1:startingfulldatafilebackupset
RMAN-08502:set_count=5set_stamp=494177612creation_time=16-MAY-03
RMAN-08010:channelc1:specifyingdatafile(s)inbackupset
RMAN-08522:inputdatafilefno=00003name=D:OracleORADATATESTUSER01.DBF
RMAN-08013:channelc1:piece1created
RMAN-08503:piecehandle=D:BACKUPTSUSER_05EN93AC_5_1comment=NONE
RMAN-08525:backupsetcomplete,elapsedtime:00:00:01
RMAN-03023:executingcommand:partialresync
RMAN-08003:startingpartialresyncofrecoverycatalog
RMAN-08005:partialresynccomplete
RMAN-03022:compilingcommand:release
RMAN-03023:executingcommand:release
RMAN-08031:releasedchannel:c1
RMAN>
3、持续在测试表中拔出纪录
SQL>insertintotestvalues(2);
1rowinserted
SQL>commit;
Commitcomplete
SQL>select*fromtest;
A
---------------------------------------
1
2
SQL>altersystemswitchlogfile;
Systemaltered.
SQL>r
1*altersystemswitchlogfile;
Systemaltered.
4、封闭数据库,摹拟丧失数据文件
SQL>shutdownimmediate;
Databaseclosed.
Databasedismounted.
Oracleinstanceshutdown
C:>delD:OracleORADATATESTUSER01.DBF
5、启动数据库,反省毛病
SQL>startup
Oracleinstancestarted.
TotalSystemGlobalArea102020364bytes
FixedSize70924bytes
VariableSize85487616bytes
DatabaseBuffers16384000bytes
RedoBuffers77824bytes
Databasemounted.
ORA-01157:cannotidentify/lockdatafile3-seeDBWRtracefile
ORA-01110:datafile3:D:OracleORADATATESTUSER01.DBF
6、先翻开数据库
SQL>alterdatabasedatafile3offlinedrop;
Databasealtered.
SQL>alterdatabaseopen;
Databasealtered.
7、恢复该表空间
恢复剧本能够是恢复单个数据文件
run{
allocatechannelc1typedisk;
restoredatafile3;
recoverdatafile3;
sqlalterdatabasedatafile3online;
releasechannelc1;
}
也能够是,恢复表空间
run{
allocatechannelc1typedisk;
restoretablespaceusers;
recovertablespaceusers;
sqlalterdatabasedatafile3online;
releasechannelc1;
}
历程以下:
C:>rman
RecoveryManager:Release8.1.6.0.0-Production
RMAN>connectrcvcatrman/rman@back
RMAN-06008:connectedtorecoverycatalogdatabase
RMAN>connecttargetinternal/virpure
RMAN-06005:connectedtotargetdatabase:TEST(DBID=1788174720)
RMAN>run{
2>allocatechannelc1typedisk;
3>restoredatafile3;
4>recoverdatafile3;
5>sqlalterdatabasedatafile3online;
6>releasechannelc1;
7>}
//输入内容冗杂,省略--编者
RMAN>
8、反省数据是不是完全
SQL>alterdatabaseopen;
Databasealtered.
SQL>select*fromtest;
A
---------------------------------------
1
2
申明:
1、RMAN也能够完成单个表空间或数据文件的恢复,恢复历程能够在mount下或open体例下,假如在open体例下恢复,能够削减down机工夫;
2、假如破坏的是一个数据文件,倡议offline并在open体例下恢复;
3、这里能够看到,RMAN举行数据文件与表空间恢复的时分,代码都对照复杂,并且能包管备份与恢复的牢靠性,以是倡议接纳RMAN的备份与恢复.
4.3丧失多个数据文件,完成全部数据库的恢复.
4.3.1OS备份计划
OS备份回档形式下破坏(丧失)多个数据文件,举行全部数据库的恢复
1、毗连数据库,创立测试表并拔出纪录
SQL>connectinternal/passwordassysdba;
Connected.
SQL>createtabletest(aint);
Tablecreated
SQL>insertintotestvalues(1);
1rowinserted
SQL>commit;
Commitcomplete
2、备份数据库,备份除一时数据文件后的所数据文件
SQL>@hotbak.sql或在DOS下svrmgrl@hotbak.sql
3、持续在测试表中拔出纪录
SQL>insertintotestvalues(2);
1rowinserted
SQL>commit;
Commitcomplete
SQL>select*fromtest;
A
---------------------------------------
1
2
SQL>altersystemswitchlogfile;
Systemaltered.
SQL>altersystemswitchlogfile;
Systemaltered.
4、封闭数据库,摹拟丧失数据文件
SQL>shutdownimmediate;
Databaseclosed.
Databasedismounted.
Oracleinstanceshutdown
C:>delD:OracleORADATATESTYSTEM01.DBF
C:>delD:OracleORADATATESTINDX01.DBF
C:>delD:OracleORADATATESTTOOLS01.DBF
C:>delD:OracleORADATATESTRBS01.DBF
摹拟媒体损坏(这里删除多个数据文件)
5、启动数据库,反省毛病
SQL>STARTUP
Oracleinstancestarted.
TotalSystemGlobalArea102020364bytes
FixedSize70924bytes
VariableSize85487616bytes
DatabaseBuffers16384000bytes
RedoBuffers77824bytes
Databasemounted.
ORA-01157:cannotidentify/lockdatafile1-seeDBWRtracefile
ORA-01110:datafile1:D:OracleORADATATESTYSTEM01.DBF
具体信息能够检察报警文件
ORA-1157signalledduring:ALTERDATABASEOPEN...
ThuMay0809:39:362003
ErrorsinfileD:Oracleadmin estdump estDBW0.TRC:
ORA-01157:cannotidentify/lockdatafile1-seeDBWRtracefile
ORA-01110:datafile1:D:OracleORADATATESTYSTEM01.DBF
ORA-27041:unabletoopenfile
OSD-04002:unabletoopenfile
O/S-Error:(OS2)体系找不到指定的文件。
ThuMay0809:39:362003
ErrorsinfileD:Oracleadmin estdump estDBW0.TRC:
ORA-01157:cannotidentify/lockdatafile2-seeDBWRtracefile
ORA-01110:datafile2:D:OracleORADATATESTRBS01.DBF
ORA-27041:unabletoopenfile
OSD-04002:unabletoopenfile
O/S-Error:(OS2)体系找不到指定的文件。
ThuMay0809:39:362003
ErrorsinfileD:Oracleadmin estdump estDBW0.TRC:
ORA-01157:cannotidentify/lockdatafile5-seeDBWRtracefile
ORA-01110:datafile5:D:OracleORADATATESTTOOLS01.DBF
ORA-27041:unabletoopenfile
OSD-04002:unabletoopenfile
O/S-Error:(OS2)体系找不到指定的文件。
ThuMay0809:39:362003
ErrorsinfileD:Oracleadmin estdump estDBW0.TRC:
ORA-01157:cannotidentify/lockdatafile6-seeDBWRtracefile
ORA-01110:datafile6:D:OracleORADATATESTINDX01.DBF
ORA-27041:unabletoopenfile
OSD-04002:unabletoopenfile
O/S-Error:(OS2)体系找不到指定的文件。
经由过程查询v$recover_file能够看到
SQL>select*fromv$recover_file;
FILE#ONLINEERRORCHANGE#TIME
--------------------------------------------------------
1ONLINEFILENOTFOUND0
2ONLINEFILENOTFOUND0
5ONLINEFILENOTFOUND0
6ONLINEFILENOTFOUND0
有四个数据文件必要恢复
6、拷贝备份回到原地址(restore),入手下手恢单数据库(recover)
restore历程:
C:>copyD:DATABAKYSTEM01.DBFD:OracleORADATATEST
C:>copyD:DATABAKTESTINDX01.DBFD:OracleORADATATEST
C:>copyD:DATABAKTESTTOOLS01.DBFD:OracleORADATATEST
C:>copyD:DATABAKTESTRBS01.DBF.DBFD:OracleORADATATEST
Recover历程:
SQL>recoverdatabase;
ORA-00279:change1073849generatedat05/08/200308:58:35neededforthread1
ORA-00289:suggestion:D:OracleORADATATESTARCHIVETESTT001S00311.ARC
ORA-00280:change1073849forthread1isinsequence#311
Specifylog:{<RET>=suggested|filename|AUTO|CANCEL}
auto
ORA-00279:change1073856generatedat05/08/200309:03:27neededforthread1
ORA-00289:suggestion:D:OracleORADATATESTARCHIVETESTT001S00312.ARC
ORA-00280:change1073856forthread1isinsequence#312
ORA-00278:logfileD:OracleORADATATESTARCHIVETESTT001S00311.ARCno
longerneededforthisrecovery
ORA-00279:change1073858generatedat05/08/200309:11:43neededforthread1
ORA-00289:suggestion:D:OracleORADATATESTARCHIVETESTT001S00313.ARC
ORA-00280:change1073858forthread1isinsequence#313
ORA-00278:logfileD:OracleORADATATESTARCHIVETESTT001S00312.ARCno
longerneededforthisrecovery
ORA-00279:change1073870generatedat05/08/200309:11:46neededforthread1
ORA-00289:suggestion:D:OracleORADATATESTARCHIVETESTT001S00314.ARC
ORA-00280:change1073870forthread1isinsequence#314
ORA-00278:logfileD:OracleORADATATESTARCHIVETESTT001S00313.ARCno
longerneededforthisrecovery
Logapplied.
Mediarecoverycomplete.
7、翻开数据库,反省数据库的数据(完整恢复)
SQL>alterdatabaseopen;
Databasealtered.
SQL>select*fromtest;
A
---------------------------------------
1
2
申明:
1、只需有备份与回档存在,就能够完成数据库的完整恢复(不丧失数据);
2、合适于丧失大批数据文件,或包括体系数据文件在内的数据库的恢复;
3、恢复历程在mount下举行,假如恢复乐成,再翻开数据库,down机工夫大概对照长一些。
4.3.2RMAN备份计划
RMAN备份回档形式下破坏(丧失)多个数据文件,举行全部数据库的恢复
1、毗连数据库,创立测试表并拔出纪录
SQL>connectinternal/passwordassysdba;
Connected.
SQL>createtabletest(aint);
Tablecreated
SQL>insertintotestvalues(1);
1rowinserted
SQL>commit;
Commitcomplete
2、备份数据库
DOS下C:>mancmdfile=bakup.rcvmsglog=backup.log;
以下是backup.log内容。
RecoveryManager:Release8.1.6.0.0-Production
RMAN>#script:bakup.rcv
2>#creater:chenjiping
3>#date:5.8.2003
4>#desc:backupalldatabasedatafileinarchivewithrman
5>
6>#connectdatabase
7>connectrcvcatrman/rman@back;
8>connecttargetinternal/virpure;
9>
10>#startbackupdatabase
11>run{
12>allocatechannelc1typedisk;
13>backupfulltagdbfullformatd:ackupfull%u_%s_%pdatabase
14>includecurrentcontrolfile;
15>sqlaltersystemarchivelogcurrent;
16>releasechannelc1;
17>}
18>#end
19>
RMAN-06008:connectedtorecoverycatalogdatabase
RMAN-06005:connectedtotargetdatabase:TEST(DBID=1788174720)
RMAN-03022:compilingcommand:allocate
RMAN-03023:executingcommand:allocate
RMAN-08030:allocatedchannel:c1
RMAN-08500:channelc1:sid=15devtype=DISK
RMAN-03022:compilingcommand:backup
RMAN-03023:executingcommand:backup
RMAN-08008:channelc1:startingfulldatafilebackupset
RMAN-08502:set_count=4set_stamp=494074368creation_time=15-MAY-03
RMAN-08010:channelc1:specifyingdatafile(s)inbackupset
RMAN-08522:inputdatafilefno=00002name=D:OracleORADATATESTRBS01.DBF
RMAN-08522:inputdatafilefno=00001name=D:OracleORADATATESTYSTEM01.DBF
RMAN-08011:includingcurrentcontrolfileinbackupset
RMAN-08522:inputdatafilefno=00005name=D:OracleORADATATESTTOOLS01.DBF
RMAN-08522:inputdatafilefno=00004name=D:OracleORADATATESTTEMP01.DBF
RMAN-08522:inputdatafilefno=00006name=D:OracleORADATATESTINDX01.DBF
RMAN-08522:inputdatafilefno=00003name=D:OracleORADATATESTUSER01.DBF
RMAN-08013:channelc1:piece1created
RMAN-08503:piecehandle=D:BACKUPFULL04EN5UG0_4_1comment=NONE
RMAN-08525:backupsetcomplete,elapsedtime:00:01:16
RMAN-03023:executingcommand:partialresync
RMAN-08003:startingpartialresyncofrecoverycatalog
RMAN-08005:partialresynccomplete
RMAN-03022:compilingcommand:sql
RMAN-06162:sqlstatement:altersystemarchivelogcurrent
RMAN-03023:executingcommand:sql
RMAN-03022:compilingcommand:release
RMAN-03023:executingcommand:release
RMAN-08031:releasedchannel:c1
RecoveryManagercomplete.
到这里暗示备份乐成。
3、持续在测试表中拔出纪录
SQL>insertintotestvalues(2);
1rowinserted
SQL>commit;
Commitcomplete
SQL>select*fromtest;
A
---------------------------------------
1
2
SQL>altersystemswitchlogfile;
Systemaltered.
SQL>altersystemswitchlogfile;
Systemaltered.
4、封闭数据库,摹拟丧失数据文件
SQL>shutdownimmediate;
Databaseclosed.
Databasedismounted.
Oracleinstanceshutdown
C:>delD:OracleORADATATESTYSTEM01.DBF
C:>delD:OracleORADATATESTINDX01.DBF
C:>delD:OracleORADATATESTTOOLS01.DBF
C:>delD:OracleORADATATESTRBS01.DBF
5、启动数据库,反省毛病
SQL>STARTUP
Oracleinstancestarted.
TotalSystemGlobalArea102020364bytes
FixedSize70924bytes
VariableSize85487616bytes
DatabaseBuffers16384000bytes
RedoBuffers77824bytes
Databasemounted.
ORA-01157:cannotidentify/lockdatafile1-seeDBWRtracefile
ORA-01110:datafile1:D:OracleORADATATESTYSTEM01.DBF
查询v$recover_file
SQL>select*fromv$recover_file;
FILE#ONLINEERRORCHANGE#TIME
--------------------------------------------------------
1ONLINEFILENOTFOUND0
2ONLINEFILENOTFOUND0
5ONLINEFILENOTFOUND0
6ONLINEFILENOTFOUND0
能够晓得有四个数据文件必要恢复.
6、使用RMAN举行恢复
C:>rman
RecoveryManager:Release8.1.6.0.0-Production
RMAN>connectrcvcatrman/rman@back
RMAN-06008:connectedtorecoverycatalogdatabase
RMAN>connecttargetinternal/virpure
RMAN-06005:connectedtotargetdatabase:TEST(DBID=1788174720)
RMAN>run{
2>allocatechannelc1typedisk;
3>restoredatabase;
4>recoverdatabase;
5>sqlalterdatabaseopen;
6>releasechannelc1;
7>}
RMAN-03022:compilingcommand:allocate
RMAN-03023:executingcommand:allocate
RMAN-08030:allocatedchannel:c1
RMAN-08500:channelc1:sid=17devtype=DISK
RMAN-03022:compilingcommand:restore
RMAN-03025:performingimplicitpartialresyncofrecoverycatalog
RMAN-03023:executingcommand:partialresync
RMAN-08003:startingpartialresyncofrecoverycatalog
RMAN-08005:partialresynccomplete
RMAN-03022:compilingcommand:IRESTORE
RMAN-03023:executingcommand:IRESTORE
RMAN-08016:channelc1:startingdatafilebackupsetrestore
RMAN-08502:set_count=4set_stamp=494074368creation_time=15-MAY-03
RMAN-08089:channelc1:specifyingdatafile(s)torestorefrombackupset
RMAN-08523:restoringdatafile00001toD:OracleORADATATESTYSTEM01.DBF
RMAN-08523:restoringdatafile00002toD:OracleORADATATESTRBS01.DBF
RMAN-08523:restoringdatafile00003toD:OracleORADATATESTUSER01.DBF
RMAN-08523:restoringdatafile00004toD:OracleORADATATESTTEMP01.DBF
RMAN-08523:restoringdatafile00005toD:OracleORADATATESTTOOLS01.DBF
RMAN-08523:restoringdatafile00006toD:OracleORADATATESTINDX01.DBF
RMAN-08023:channelc1:restoredbackuppiece1
RMAN-08511:piecehandle=D:BACKUPFULL04EN5UG0_4_1tag=DBFULLparams=NULL
RMAN-08024:channelc1:restorecomplete
RMAN-03023:executingcommand:partialresync
RMAN-08003:startingpartialresyncofrecoverycatalog
RMAN-08005:partialresynccomplete
RMAN-03022:compilingcommand:recover
RMAN-03022:compilingcommand:recover(1)
RMAN-03022:compilingcommand:recover(2)
RMAN-03022:compilingcommand:recover(3)
RMAN-03023:executingcommand:recover(3)
RMAN-08054:startingmediarecovery
RMAN-03022:compilingcommand:recover(4)
RMAN-06050:archivelogthread1sequence327isalreadyondiskasfileD:OracleORADATATESTARCHIVETESTT001S00327.ARC
RMAN-06050:archivelogthread1sequence328isalreadyondiskasfileD:OracleORADATATESTARCHIVETESTT001S00328.ARC
RMAN-06050:archivelogthread1sequence329isalreadyondiskasfileD:OracleORADATATESTARCHIVETESTT001S00329.ARC
RMAN-06050:archivelogthread1sequence330isalreadyondiskasfileD:OracleORADATATESTARCHIVETESTT001S00330.ARC
RMAN-03023:executingcommand:recover(4)
RMAN-08515:archivelogfilename=D:OracleORADATATESTARCHIVETESTT001S00327.ARCthread=1sequence=327
RMAN-08515:archivelogfilename=D:OracleORADATATESTARCHIVETESTT001S00328.ARCthread=1sequence=328
RMAN-08055:mediarecoverycomplete
RMAN-03022:compilingcommand:sql
RMAN-06162:sqlstatement:alterdatabaseopen
RMAN-03023:executingcommand:sql
RMAN-03022:compilingcommand:release
RMAN-03023:executingcommand:release
RMAN-08031:releasedchannel:c1
RMAN>
7、反省数据库的数据(完整恢复)
SQL>select*fromtest;
A
---------------------------------------
1
2
申明:
1、只需有备份与回档存在,RMAN也能够完成数据库的完整恢复(不丧失数据);
2、同OS备份数据库恢复,合适于丧失大批数据文件,或包括体系数据文件在内的数据库的恢复;
3、方针数据库在mount下举行,假如恢复乐成,再翻开数据库;
4、RMAN的备份与恢复命令绝对对照复杂并牢靠,倡议有前提的话,都接纳RMAN举行数据库的备份。
4.4不完整恢复案例
4.4.1OS备份下的基于工夫的恢复
不完整恢复能够分为基于工夫的恢复,基于改动的恢复与基于取消的恢复,这里已基于工夫的恢复为例子来讲明不完整恢复历程。
基于工夫的恢复能够不完整恢复到如今工夫之前的某一个工夫,关于某些误操纵,如删除一个数据表,能够在备用恢复情况上恢复到表的删除工夫之前,然后把该表导出到正式情况,制止一团体为的毛病。
1、毗连数据库,创立测试表并拔出纪录:
SQL>connectinternal/passwordassysdba;
Connected.
SQL>createtabletest(aint);
Tablecreated
SQL>insertintotestvalues(1);
1rowinserted
SQL>commit;
Commitcomplete
2、备份数据库,这里最好备份一切的数据文件,包含一时数据文件:
SQL>@hotbak.sql或在DOS下svrmgrl@hotbak.sql
或冷备份也能够
3、删除测试表,假定删除前的工夫为T1,在删除之前,便于测试,持续拔出数据并使用到回
档。
SQL>insertintotestvalues(2);
1rowinserted
SQL>commit;
Commitcomplete
SQL>select*fromtest;
A
---------------------------------------
1
2
SQL>altersystemswitchlogfile;
Statementprocessed.
SQL>altersystemswitchlogfile;
Statementprocessed.
SQL>selectto_char(sysdate,yyyy-mm-ddhh24:mi:ss)fromdual;
TO_CHAR(SYSDATE,YY
-------------------
2003-05-2114:43:01
SQL>droptabletest;
Tabledropped.
4、筹办恢复到工夫点T1,找回删除的表,先封闭数据库:
SQL>shutdownimmediate;
Databaseclosed.
Databasedismounted.
Oracleinstanceshutdown.
5、拷贝方才备份的一切数据文件返来
C:>copyD:DATABAK*.DBFD:OracleORADATATEST
6、启动到mount下
SQL>startupmount;
Oracleinstancestarted.
TotalSystemGlobalArea102020364bytes
FixedSize70924bytes
VariableSize85487616bytes
DatabaseBuffers16384000bytes
RedoBuffers77824bytes
Databasemounted.
7、入手下手不完整恢单数据库到T1工夫
SQL>recoverdatabaseuntiltime2003-05-21:14:43:01;
ORA-00279:change30944generatedat05/21/200314:40:06neededforthread1
ORA-00289:suggestion:D:OracleORADATATESTARCHIVETESTT001S00191.ARC
ORA-00280:change30944forthread1isinsequence#191
Specifylog:{<RET>=suggested|filename|AUTO|CANCEL}
auto
Logapplied.
Mediarecoverycomplete.
8、翻开数据库,反省数据
SQL>alterdatabaseopenresetlogs;
Databasealtered.
SQL>select*fromtest;
A
---------------------------------------
1
2
申明:
1、不完整恢复最好备份一切的数据,冷备份亦可,由于恢复历程是从备份点今后恢复的,假如由于个中一个数据文件的工夫戳(SCN)年夜于要恢复的工夫点,那末恢复都是不成能乐成的;
2、不完整恢复有三种体例,历程都一样,仅仅是recover命令有所纷歧样,这里用基于工夫的恢复作为示例;
3、不完整恢复以后,都必需用resetlogs的体例翻开数据库,倡议即刻再做一次全备份,由于resetlogs以后再用之前的备份恢复是很难了;
4、以上是在删除之前取得工夫,可是实践使用中,很难晓得删除之前的实践工夫,但能够接纳大抵工夫便可,或能够接纳剖析日记文件(logmnr),获得准确的必要恢复的工夫;
5、一样平常都是在测试机后备用呆板上接纳这类不完整恢复,恢复以后导出/导进被误删的表复生产体系.
4.4.2RMAN备份下的基于改动的恢复
以上用OS备份申明了一个基于工夫的恢复,如今用RMAN申明一个基于改动的恢复
1、毗连数据库,创立测试表并拔出纪录
SQL>connectinternal/passwordassysdba;
Connected.
SQL>createtabletest(aint);
Tablecreated
SQL>insertintotestvalues(1);
1rowinserted
SQL>commit;
Commitcomplete
2、备份数据库
C:>rman
RecoveryManager:Release8.1.6.0.0-Production
RMAN>connectrcvcatrman/rman@back
RMAN-06008:connectedtorecoverycatalogdatabase
RMAN>connecttargetinternal/virpure
RMAN-06005:connectedtotargetdatabase:TEST(DBID=874705288)
RMAN>run{
2>allocatechannelc1typedisk;
3>backupfulltagdbfullformatd:ackupfull%u_%s_%pdatabase
4>includecurrentcontrolfile;
5>sqlaltersystemarchivelogcurrent;
6>releasechannelc1;
7>}
//屏幕输入内容冗杂,省略--编纂
RMAN>
3、删除测试表,在删除之前,便于测试,持续拔出数据并使用到回档,并猎取删除前的scn号。
SQL>insertintotestvalues(2);
1rowinserted
SQL>commit;
Commitcomplete
SQL>select*fromtest;
A
---------------------------------------
1
2
SQL>altersystemswitchlogfile;
Statementprocessed.
SQL>altersystemswitchlogfile;
Statementprocessed.
SQL>selectmax(ktuxescnw*power(2,32)+ktuxescnb)scnfromx$ktuxe;
SCN
----------
31014
SQL>droptabletest;
Tabledropped.
4、筹办恢复到SCN31014,先封闭数据库,然后启动到mount下
SQL>shutdownimmediate;
Databaseclosed.
Databasedismounted.
Oracleinstanceshutdown.
SQL>startupmount;
5、入手下手恢复到改动点SCN31014
RMAN>run{
2>allocatechannelc1typedisk;
3>restoredatabase;
4>recoverdatabaseuntilscn31014;
5>sqlALTERDATABASEOPENRESETLOGS;
6>releasechannelc1;
7>}
RMAN-03022:compilingcommand:allocate
RMAN-03023:executingcommand:allocate
RMAN-08030:allocatedchannel:c1
RMAN-08500:channelc1:sid=10devtype=DISK
RMAN-03022:compilingcommand:restore
RMAN-03022:compilingcommand:IRESTORE
RMAN-03023:executingcommand:IRESTORE
RMAN-08016:channelc1:startingdatafilebackupsetrestore
RMAN-08502:set_count=1set_stamp=494613682creation_time=21-MAY-03
RMAN-08089:channelc1:specifyingdatafile(s)torestorefrombackupset
RMAN-08523:restoringdatafile00001toD:OracleORADATATESTYSTEM01.DBF
RMAN-08523:restoringdatafile00002toD:OracleORADATATESTRBS01.DBF
RMAN-08523:restoringdatafile00003toD:OracleORADATATESTUSERS01.DBF
RMAN-08523:restoringdatafile00004toD:OracleORADATATESTTEMP01.DBF
RMAN-08523:restoringdatafile00005toD:OracleORADATATESTTOOLS01.DBF
RMAN-08523:restoringdatafile00006toD:OracleORADATATESTINDX01.DBF
RMAN-08023:channelc1:restoredbackuppiece1
RMAN-08511:piecehandle=D:BACKUPFULL01ENMD5I_1_1tag=DBFULLparams=NULL
RMAN-08024:channelc1:restorecomplete
RMAN-03023:executingcommand:partialresync
RMAN-08003:startingpartialresyncofrecoverycatalog
RMAN-08005:partialresynccomplete
RMAN-03022:compilingcommand:recover
RMAN-03022:compilingcommand:recover(1)
RMAN-03022:compilingcommand:recover(2)
RMAN-03022:compilingcommand:recover(3)
RMAN-03023:executingcommand:recover(3)
RMAN-08054:startingmediarecovery
RMAN-03022:compilingcommand:recover(4)
RMAN-06050:archivelogthread1sequence191isalreadyondiskasfileD:ORACL
EORADATATESTARCHIVETESTT001S00191.ARC
RMAN-06050:archivelogthread1sequence192isalreadyondiskasfileD:ORACL
EORADATATESTARCHIVETESTT001S00192.ARC
RMAN-03023:executingcommand:recover(4)
RMAN-08515:archivelogfilename=D:OracleORADATATESTARCHIVETESTT001S00191.AR
Cthread=1sequence=191
RMAN-08515:archivelogfilename=D:OracleORADATATESTARCHIVETESTT001S00192.ARC
Thread=1sequence=192
RMAN-08055:mediarecoverycomplete
RMAN-03022:compilingcommand:sql
RMAN-06162:sqlstatement:ALTERDATABASEOPENRESETLOGS
RMAN-03023:executingcommand:sql
RMAN-03022:compilingcommand:release
RMAN-03023:executingcommand:release
RMAN-08031:releasedchannel:c1
6、反省数据
Databasealtered.
SQL>select*fromtest;
A
---------------------------------------
1
2
能够看到,表仍然存在。
申明:
1、RMAN也能够完成不完整恢复,办法比OS备份恢复的办法更复杂牢靠;
2、RMAN能够基于工夫,基于改动与基于日记序列的不完整恢复,基于日记序列的恢复能够指定恢复到哪一个日记序列,如
run{
allocatechannelch1typedisk;
allocatechannelch2typesbt_tape;
setuntillogseq1234thread1;
restorecontrolfileto$Oracle_HOME/dbs/cf1.f;
replicatecontrolfilefrom$Oracle_HOME/dbs/cf1.f;
alterdatabasemount;
restoredatabase;
recoverdatabase;
sql"ALTERDATABASEOPENRESETLOGS";
}
3、与一切的不完整恢复一样,必需在mount下,restore一切备份数据文件,必要resetlogs;
4、基于改动的恢复比基于工夫的恢复更牢靠,可是大概也更庞大,必要晓得必要恢复到哪个改动号(SCN),在一般临盆中,猎取SCN的举措实在也有良多,如查询数据库字典表(V$archived_logorv$log_history),或剖析回档与联机日记(logmnr)等。
第五章别的恢复案例
5.1破坏联机日记的恢复办法
5.1.1破坏非以后联机日记
人人都分明,联机日记分为以后联机日记和非以后联机日记,非以后联机日记的破坏是对照复杂的,一样平常经由过程clear命令就能够办理成绩。
1、启动数据库,碰到ORA-00312orORA-00313毛病,如
ORA-00313:openfailedformembersofloggroup1ofthread1
ORA-00312:onlinelog1thread1:D:OracleORADATATESTREDO01.LOG
从这里我们晓得越来越多的开发者将继续选择MySQL。Evans的总裁JohnAndrews表示,MySQL学习教程用户对MySQL和其他开源数据库的评价正在赶上甚至超过很多专有商业数据库软件。 |
|