首页 运维 正文
跳过rman坏块进行数据恢复

 2022-10-23    415  

在有些情况下,我们仅有一份rman备份,而这个时候rman 备份有出现坏块,使得我们的还原/恢复工作无法继续下去,导致数据大量丢失。我们可以通过设置event 19548/19549来跳过坏块,***程度抢救数据。

rman备份数据文件

C:\Users\XIFENFEI>rmantarget/
RecoveryManager:Release11.2.0.3.0-ProductiononThuJun620:31:192013
Copyright(c)1982,2011,Oracleand/oritsaffiliates.Allrightsreserved.
connectedtotargetdatabase:XIFENFEI(DBID=1422012639)
RMAN>backuptablespaceusersformat'f:/users_bak.rman';
Startingbackupat06-JUN-13
usingtargetdatabasecontrolfileinsteadofrecoverycatalog
allocatedchannel:ORA_DISK_1
channelORA_DISK_1:SID=197devicetype=DISK
channelORA_DISK_1:startingfulldatafilebackupset
channelORA_DISK_1:specifyingdatafile(s)inbackupset
inputdatafilefilenumber=00004name=E:\ORACLE\ORADATA\XIFENFEI\USERS01.DBF
channelORA_DISK_1:startingpiece1at06-JUN-13
channelORA_DISK_1:finishedpiece1at06-JUN-13
piecehandle=F:\USERS_BAK.RMANtag=TAG20130606T203154comment=NONE
channelORA_DISK_1:backupsetcomplete,elapsedtime:00:00:03
Finishedbackupat06-JUN-13

切换归档日志

SQL>altersystemswitchlogfile;
Systemaltered.
SQL>/
Systemaltered.
SQL>/
Systemaltered.
SQL>archiveloglist;
DatabaselogmodeArchiveMode
AutomaticarchivalEnabled
ArchivedestinationE:\oracle\product\11.2.0\dbhome_1\RDBMS
Oldestonlinelogsequence95
Nextlogsequencetoarchive97
Currentlogsequence97

重命名数据文件

SQL>shutdownimmediate
Databaseclosed.
Databasedismounted.
ORACLEinstanceshutdown.
--------------------------------------
e:\oracle\oradata\XIFENFEI>moveUSERS01.DBFUSERS01_bak.DBF
移动了1个文件。
--------------------------------------
SQL>startup
ORACLEinstancestarted.
TotalSystemGlobalArea418484224bytes
FixedSize1385052bytes
VariableSize327159204bytes
DatabaseBuffers83886080bytes
RedoBuffers6053888bytes
Databasemounted.
ORA-01157:cannotidentify/lockdatafile4-seeDBWRtracefile
ORA-01110:datafile4:'E:\ORACLE\ORADATA\XIFENFEI\USERS01.DBF'

#p#

破坏备份集

破坏前

破坏后

这里很明显,我通过ue把rman备份集中的T修改为了A,肯定破坏了文件,使之出现坏块

rman还原数据文件

C:\Users\XIFENFEI>rmantarget/
RecoveryManager:Release11.2.0.3.0-ProductiononThuJun621:02:412013
Copyright(c)1982,2011,Oracleand/oritsaffiliates.Allrightsreserved.
connectedtotargetdatabase:XIFENFEI(DBID=1422012639,notopen)
RMAN>restoredatafile4;
Startingrestoreat06-JUN-13
usingtargetdatabasecontrolfileinsteadofrecoverycatalog
allocatedchannel:ORA_DISK_1
channelORA_DISK_1:SID=63devicetype=DISK
channelORA_DISK_1:startingdatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
channelORA_DISK_1:restoringdatafile00004toE:\ORACLE\ORADATA\XIFENFEI\USERS
01.DBF
channelORA_DISK_1:readingfrombackuppieceF:\USERS_BAK.RMAN
channelORA_DISK_1:ORA-19870:errorwhilerestoringbackuppieceF:\USERS_BAK.R
MAN
ORA-19612:datafile4notrestoredduetomissingorcorruptdata
failovertopreviousbackup
creatingdatafilefilenumber=4name=E:\ORACLE\ORADATA\XIFENFEI\USERS01.DBF
Finishedrestoreat06-JUN-13

这里可以清晰的看到rman报ORA-19612错误,restore 失败,alert日志为:

ThuJun0621:02:312013
ALTERDATABASEOPEN
ErrorsinfileE:\ORACLE\diag\rdbms\xifenfei\xff\trace\xff_dbw0_7400.trc:
ORA-01157:????/??????4-???DBWR????
ORA-01110:????4:'E:\ORACLE\ORADATA\XIFENFEI\USERS01.DBF'
ORA-27041:??????
OSD-04002:unabletoopenfile
O/S-Error:(OS2)系统找不到指定的文件。
ErrorsinfileE:\ORACLE\diag\rdbms\xifenfei\xff\trace\xff_ora_4272.trc:
ORA-01157:cannotidentify/lockdatafile4-seeDBWRtracefile
ORA-01110:datafile4:'E:\ORACLE\ORADATA\XIFENFEI\USERS01.DBF'
ORA-1157signalledduring:ALTERDATABASEOPEN...
ThuJun0621:02:332013
Checkerrunfound1newpersistentdatafailures
ThuJun0621:03:232013
Corruptblock101foundduringreadingbackuppiece,file=F:\USERS_BAK.RMAN,corr_type=3
Rereadofblocknum=101,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=101,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=101,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=101,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=101,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
ContinuingreadingpieceF:\USERS_BAK.RMAN,noothercopiesavailable.

rman备份集有坏块,导致rman还原无法正常进行下去,还原后的数据文件大小。

#p#

观察已经正常还原出来数据文件情况

SQL>selectCHECKPOINT_CHANGE#,file#fromv$datafile_header;
CHECKPOINT_CHANGE#FILE#
----------------------------
15715821
15715822
15715823
183794
15715825
15715826
15715827
SQL>recoverdatabasedatafile4;
ORA-00274:illegalrecoveryoptionDATAFILE
SQL>recoverdatafile4;
ORA-00279:change18379generatedat01/20/201317:13:56neededforthread1
ORA-00289:suggestion:
E:\ORACLE\PRODUCT\11.2.0\DBHOME_1\RDBMS\ARC0000000001_0805223583.0001
ORA-00280:change18379forthread1isinsequence#1
Specifylog:{<RET>=suggested|filename|AUTO|CANCEL}

rman只是还原了很小的一部分文件,做恢复提示需要从归档日志seq 1开始(某些情况可能需要其他归档,总之不是正常情况),证明rman还原异常

设置event事件还原

SQL>shutdownabort;
ORACLEinstanceshutdown.
SQL>startuppfile='e:/pfile.txt'mount;
ORACLEinstancestarted.
TotalSystemGlobalArea418484224bytes
FixedSize1385052bytes
VariableSize327159204bytes
DatabaseBuffers83886080bytes
RedoBuffers6053888bytes
Databasemounted.
SQL>showparameterevent;
NAMETYPEVALUE
-----------------------------------------------------------------------------
eventstring19548tracenamecontextforev
er,19549tracenamecontextf
orever
Event19548:Thiswillattempttorestorecontentofthecorruptedblockifitispossible.
Event19549:Thiswillsuppresserroringoutduringrestore

rman还原数据文件

RMAN>restoredatafile4;
Startingrestoreat06-JUN-13
usingtargetdatabasecontrolfileinsteadofrecoverycatalog
allocatedchannel:ORA_DISK_1
channelORA_DISK_1:SID=63devicetype=DISK
channelORA_DISK_1:startingdatafilebackupsetrestore
channelORA_DISK_1:specifyingdatafile(s)torestorefrombackupset
channelORA_DISK_1:restoringdatafile00004toE:\ORACLE\ORADATA\XIFENFEI\USERS
01.DBF
channelORA_DISK_1:readingfrombackuppieceF:\USERS_BAK.RMAN
channelORA_DISK_1:piecehandle=F:\USERS_BAK.RMANtag=TAG20130606T203154
channelORA_DISK_1:restoredbackuppiece1
channelORA_DISK_1:restorecomplete,elapsedtime:00:00:35
Finishedrestoreat06-JUN-13

这里证明数据库rman有坏块通过rman还原成功,alert日志提示如下:

ThuJun0621:29:532013
WARNING:Theblockthatappearstobeblocknumber100
infile4iscorruptinbackuppieceF:\USERS_BAK.RMAN.
Suchblockswouldusuallybeformattedasempty
intherestoredfile,butevent19548hasbeen
settoincludetheblockas-isintherestored
file.
Corruptblock102foundduringreadingbackuppiece,file=F:\USERS_BAK.RMAN,corr_type=-2
Rereadofblocknum=102,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=102,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=102,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=102,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=102,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
ContinuingreadingpieceF:\USERS_BAK.RMAN,noothercopiesavailable.
…………
Corruptblock258foundduringreadingbackuppiece,file=F:\USERS_BAK.RMAN,corr_type=-2
Rereadofblocknum=258,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=258,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=258,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=258,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
Rereadofblocknum=258,file=F:\USERS_BAK.RMAN,foundsamecorruptdata
ContinuingreadingpieceF:\USERS_BAK.RMAN,noothercopiesavailable.
WARNING:somedatainthebackupoffile4wasmissing
orcorrupt.Event19549hasbeensettoallow
thefiletoberestoredanyway.
backupheaderblockcount:5369
backupactualblockcount:5212
backupheaderchecksum:-218250743
backupactualchecksum:1442665538
Fullrestorecompleteofdatafile4E:\ORACLE\ORADATA\XIFENFEI\USERS01.DBF.Elapsedtime:0:00:25
checkpointis1570136
lastdeallocationscnis1508457

这里rman还原依然遇到很多坏块,但是均跳过坏块,还是完整的恢复出来的数据文件(大小)。

#p#

rman还原数据文件

RMAN>recoverdatafile4;
Startingrecoverat06-JUN-13
usingchannelORA_DISK_1
startingmediarecovery
archivedlogforthread1withsequence94isalreadyondiskasfileE:\ORACLE\
PRODUCT\11.2.0\DBHOME_1\RDBMS\ARC0000000094_0805223583.0001
archivedlogforthread1withsequence95isalreadyondiskasfileE:\ORACLE\
PRODUCT\11.2.0\DBHOME_1\RDBMS\ARC0000000095_0805223583.0001
archivedlogforthread1withsequence96isalreadyondiskasfileE:\ORACLE\
PRODUCT\11.2.0\DBHOME_1\RDBMS\ARC0000000096_0805223583.0001
archivedlogfilename=E:\ORACLE\PRODUCT\11.2.0\DBHOME_1\RDBMS\ARC0000000094_080
5223583.0001thread=1sequence=94
mediarecoverycomplete,elapsedtime:00:00:00
Finishedrecoverat06-JUN-13

这里可以明显的看到在recover过程中数据库应用的是备份后的所有归档,数据文件是正常被还原出来(坏块除外)。

查询对象

SQL>alterdatabaseopen;
Databasealtered.
SQL>conntest/test
Connected.
SQL>select*fromtab;
TNAMETABTYPECLUSTERID
-----------------------------------------------
STB101TABLE
SQL>selectcount(*)fromstb101;
selectcount(*)fromstb101
*
ERRORatline1:
ORA-08103:objectnolongerexists

dbv检查坏块

e:\oracle\oradata\XIFENFEI>dbvfile=USERS01.DBF
DBVERIFY:Release11.2.0.3.0-ProductiononThuJun623:59:492013
Copyright(c)1982,2011,Oracleand/oritsaffiliates.Allrightsreserved.
DBVERIFY-Verificationstarting:FILE=E:\ORACLE\ORADATA\XIFENFEI\USERS01.DBF
Page100ismarkedcorrupt
Corruptblockrelativedba:0x01000064(file4,block100)
Badcheckvaluefoundduringdbv:
Datainbadblock:
type:30format:2rdba:0x01000064
lastchangescn:0x0000.00004890seq:0x1flg:0x04
spare1:0x0spare2:0x0spare3:0x0
consistencyvalueintail:0x48901e01
checkvalueinblockheader:0x8311
computedblockchecksum:0x20
DBVERIFY-Verificationcomplete
TotalPagesExamined:12320
TotalPagesProcessed(Data):4952
TotalPagesFailing(Data):0
TotalPagesProcessed(Index):0
TotalPagesFailing(Index):0
TotalPagesProcessed(Other):7069
TotalPagesProcessed(Seg):0
TotalPagesFailing(Seg):0
TotalPagesEmpty:298

证明设置了event之后,rman确实跳过了备份集中的坏块,而且是直接还原了坏块内容,证明了event 19548和19549作用。

补充说明

在非特殊情况下强烈不建议设置相关event跳过rman中的坏块来还原/恢复数据库,这样将对数据的丢失,甚至数据库是否可以正常open不好评估,rman备份重要,确保rman备份可用也很重要。

原文链接:https://77isp.com/post/8547.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。