数据库修复Part1:创建自己的测试corrupt数据库
以前看Pual寫(xiě)過(guò)很多數(shù)據(jù)恢復(fù)的文章,他很多的測(cè)試都是自己創(chuàng)建的Corrupt數(shù)據(jù)庫(kù),其實(shí)我們自己也可以。
?
1. 創(chuàng)建數(shù)據(jù)庫(kù)數(shù)據(jù)表插入數(shù)據(jù):
use master
go
create databasecorrupt
?
use corrupt
go
create tabletest(IDint, namevarchar(10))
?
declare @int asint
set @int = 1
while @int <20
begin
insert intotestvalues(@int,'allentest')
set @int += 1
end
?
2. 使用DBCC IND查看Test表所在的PageID
dbcc ind(corrupt,test,1)
?
?
3. 用DBCC PAGE查看TEST表的內(nèi)容:
dbcc traceon(3604,-1)
go
dbcc page(corrupt,1,55,1)
?
?
?
這里我們只修改Slot 1數(shù)據(jù),偏移地址為78,轉(zhuǎn)化為10進(jìn)制為120.
所以當(dāng)前Slot1的實(shí)際地址為:55*8192+120=450680
?
4. 停掉SQL Server用XVI32打開(kāi)數(shù)據(jù)文件然后輸入地址找到對(duì)應(yīng)的數(shù)據(jù)(可以看到數(shù)據(jù)與Step3中看到的數(shù)據(jù)一致)。
?
?
?
5. 對(duì)數(shù)據(jù)進(jìn)行修改保存關(guān)閉XVI32。
?
6. 重啟SQL Server然后用DBCC PAGE看Page 55 Slot1內(nèi)容(已經(jīng)被更改)
7. DBCCCHECKDB檢查數(shù)據(jù)庫(kù)發(fā)現(xiàn)下面的錯(cuò)誤:
?
dbcc checkdb withno_infomsgs
?
Msg8928, Level 16, State 1, Line 1
Object ID2105058535, index ID 0, partition ID 72057594038779904, alloc unit ID72057594039828480 (type In-row data): Page (1:55) could not be processed. See other errors for details.
Msg8939, Level 16, State 98, Line 1
Table error: ObjectID 2105058535, index ID 0, partition ID 72057594038779904, alloc unit ID72057594039828480 (type In-row data), page (1:55). Test (IS_OFF (BUF_IOERR,pBUF->bstat)) failed. Values are 12716041 and -4.
這樣我們就創(chuàng)建了一個(gè)Corrupt的數(shù)據(jù)庫(kù),稍后我會(huì)花時(shí)間測(cè)試恢復(fù)(page restore/ dbcc checkdbrepair_allow_data_loss/rebuildSQL Server log),然后把測(cè)試步驟發(fā)出來(lái).
?
如果你不想自己創(chuàng)建的話,也可以使用Paul提供的兩個(gè)Corrupt數(shù)據(jù)庫(kù)做測(cè)試。
轉(zhuǎn)載于:https://blog.51cto.com/lzf328/954147
總結(jié)
以上是生活随笔為你收集整理的数据库修复Part1:创建自己的测试corrupt数据库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: HDU 4339 Query
- 下一篇: SQL Server Managemen