以前看Pual写过很多数据恢复的文章,他很多的测试都是自己创建的Corrupt数据库,其实我们自己也可以。 1. 创建数据库数据表插入数据: use master go create database corrupt use corrupt go create table test ( ID int , name varchar ( 10 )) declare @i
以前看Pual写过很多数据恢复的文章,他很多的测试都是自己创建的Corrupt数据库,其实我们自己也可以。
1. 创建数据库数据表插入数据:
use master
go
create database corrupt
use corrupt
go
create table test ( ID int , name varchar ( 10 ))
declare @int as int
begin
insert into test values ( @int , 'allentest' )
end
2. 使用 DBCC IND 查看 Test 表所在的 PageID
dbcc ind ( corrupt , test , 1 )
3. 用 DBCC PAGE 查看 TEST 表的内容:
dbcc traceon ( 3604 ,- 1 )
go
dbcc page ( corrupt , 1 , 55 , 1 )
这里我们只修改 Slot 1 数据,偏移地址为 78 ,转化为 10 进制为 120.
所以当前 Slot1 的实际地址为: 55*8192+120=450680
4. 停掉 SQL Server 用 XVI32 打开数据文件然后输入地址找到对应的数据(可以看到数据与 Step3 中看到的数据一致)。
5. 对数据进行修改保存关闭XVI32。
6. 重启 SQL Server 然后用 DBCC PAGE 看 Page 55 Slot1 内容(已经被更改)
7. DBCCCHECKDB 检查数据库发现下面的错误:
dbcc checkdb with no_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.
这样我们就创建了一个 Corrupt 的数据库,稍后我会花时间测试恢复( page restore/ dbcc checkdb repair_allow_data_loss/rebuildSQL Server log ),然后把测试步骤发出来 .
如果你不想自己创建的话,也可以使用 Paul 提供的两个 Corrupt 数据库做测试。
查看更多关于数据库修复Part1:创建自己的测试corrupt数据库的详细内容...