解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库

WBOY
リリース: 2016-06-07 15:20:56
オリジナル
1228 人が閲覧しました

解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库(译) http://improve.dk/corrupting-databases-purpose-using-orcamdf-corruptor/ 有时候你必须先作恶,后行善。情况就是 当你想磨练你的数据库修复技能 我现在添加了一个Corruptor 类到Orca

解剖SQLSERVER 第十七篇 使用 OrcaMDF Corruptor 故意损坏数据库(译)

http://improve.dk/corrupting-databases-purpose-using-orcamdf-corruptor/

有时候你必须先作恶,后行善。情况就是 当你想磨练你的数据库修复技能

我现在添加了一个Corruptor 类到OrcaMDF里面 去测试新的RawDatabase 的功能。Corruptor 就跟他的名字一样--他会故意损坏数据库文件


Corruptor 本身是比较简单的。Corruptor 会随机选择一些页面并且简单的使用0来完全复写页面。
根据页面的类型,这可能会造成致命伤害

我不想多说什么了,不过万一。。。请不要在你的生产库上运行。这会损坏你的数据。

 

例子
有两个 Corruptor.CorruptFile重载方法,他们都返回integers 的枚举值 -- 一系列的pageid 列表并且被复写0的

下面的代码会损坏5%的页面在AdventureWorks2008R2LT.mdf 文件里面,然后他会输出每个被损坏了的页面ID 。
你可以定义损坏页面的百分比 只需要改变第二个参数

<span>var</span> corruptedPageIDs = Corruptor.CorruptFile(<span>@"</span><span>C:\AdventureWorks2008R2LT.mdf</span><span>"</span>, <span>0.05</span><span>);
Console.WriteLine(</span><span>string</span>.Join(<span>"</span><span>, </span><span>"</span>, corruptedPageIDs));
ログイン後にコピー

<span>606</span>, <span>516</span>, <span>603</span>, <span>521</span>, <span>613</span>, <span>621</span>, <span>118</span>, <span>47</span>, <span>173</span>, <span>579</span><span>,
</span><span>323</span>, <span>217</span>, <span>358</span>, <span>515</span>, <span>615</span>, <span>271</span>, <span>176</span>, <span>596</span>, <span>417</span>, <span>379</span><span>,
</span><span>269</span>, <span>409</span>, <span>558</span>, <span>103</span>, <span>8</span>, <span>636</span>, <span>200</span>, <span>361</span>, <span>60</span>, <span>486</span><span>,
</span><span>366</span>, <span>99</span>, <span>87</span>
ログイン後にコピー

为了使损坏更厉害,你也可以使用第二个重载方法,他允许你定义一个确切的损坏页面的数目,在一个确定的pageid范围内。
下面的代码会确切的损坏pageid在0到49这个范围内的10个页面,因此会损坏大部分的元数据,大家知道系统表的数据基本都存储在数据库最靠前的页面上

<span>var</span> corruptedPageIDs = Corruptor.CorruptFile(<span>@"</span><span>C:\AdventureWorks2008R2LT.mdf</span><span>"</span>, <span>10</span>, <span>0</span>, <span>49</span><span>);
Console.WriteLine(</span><span>string</span>.Join(<span>"</span><span>, </span><span>"</span>, corruptedPageIDs));
ログイン後にコピー

<span>16</span>, <span>4</span>, <span>0</span>, <span>32</span>, <span>15</span>, <span>14</span>, <span>30</span>, <span>2</span>, <span>49</span>, <span>9</span>
ログイン後にコピー

 

在上面的情况我非常不幸的看到 下面这些页面都被填充了0 包括:

file header page,page 2 is the first GAM page,page 9 is the boot page ,page 16 allocation unit metadata。

这样的损坏程度,即使使用DBCC CHECKDB也没办法修复,留下给你的选择只有从备份中还原

 

或者,你可以尝试一下使用OrcaMDF RawDatabase去恢复尽可能多的数据,先到这里了,我以后还会继续介绍。

 

<span>DBCC</span> TRACEON(<span>3604</span>,<span>-</span><span>1</span><span>)
</span><span>GO</span>

<span>DBCC</span> PAGE(<span>[</span><span>sss</span><span>]</span>,<span>1</span>,<span>16</span>,<span>3</span><span>)
</span><span>GO</span>

<span>DBCC</span> 执行完毕。如果 <span>DBCC</span><span> 输出了错误信息,请与系统管理员联系。

PAGE: (</span><span>1</span>:<span>16</span><span>)


BUFFER:


BUF </span><span>@0x0000000080FDEB80</span><span>

bpage </span><span>=</span> <span>0x0000000080A74000</span> bhash <span>=</span> <span>0x0000000000000000</span> bpageno <span>=</span> (<span>1</span>:<span>16</span><span>)
bdbid </span><span>=</span> <span>8</span> breferences <span>=</span> <span>0</span> bcputicks <span>=</span> <span>0</span><span>
bsampleCount </span><span>=</span> <span>0</span> bUse1 <span>=</span> <span>19980</span> bstat <span>=</span> <span>0xc00009</span><span>
blog </span><span>=</span> <span>0x32159</span> bnext <span>=</span> <span>0x0000000000000000</span><span>

PAGE HEADER:


Page </span><span>@0x0000000080A74000</span><span>

m_pageId </span><span>=</span> (<span>1</span>:<span>16</span>) m_headerVersion <span>=</span> <span>1</span> m_type <span>=</span> <span>1</span><span>
m_typeFlagBits </span><span>=</span> <span>0x4</span> m_level <span>=</span> <span>0</span> m_flagBits <span>=</span> <span>0x200</span><span>
m_objId (AllocUnitId.idObj) </span><span>=</span> <span>7</span> m_indexId (AllocUnitId.idInd) <span>=</span> <span>0</span> Metadata: AllocUnitId <span>=</span> <span>458752</span><span>
Metadata: PartitionId </span><span>=</span> <span>458752</span> Metadata: IndexId <span>=</span> <span>1</span> Metadata: ObjectId <span>=</span> <span>7</span><span>
m_prevPage </span><span>=</span> (<span>0</span>:<span>0</span>) m_nextPage <span>=</span> (<span>1</span>:<span>130</span>) pminlen <span>=</span> <span>73</span><span>
m_slotCnt </span><span>=</span> <span>49</span> m_freeCnt <span>=</span> <span>4225</span> m_freeData <span>=</span> <span>4331</span><span>
m_reservedCnt </span><span>=</span> <span>0</span> m_lsn <span>=</span> (<span>1037</span>:<span>459</span>:<span>3</span>) m_xactReserved <span>=</span> <span>0</span><span>
m_xdesId </span><span>=</span> (<span>0</span>:<span>455</span>) m_ghostRecCnt <span>=</span> <span>0</span> m_tornBits <span>=</span> <span>-</span><span>563242027</span><span>

Allocation Status

GAM (</span><span>1</span>:<span>2</span>) <span>=</span> ALLOCATED SGAM (<span>1</span>:<span>3</span>) <span>=</span> <span>NOT</span><span> ALLOCATED 
PFS (</span><span>1</span>:<span>1</span>) <span>=</span> <span>0x60</span> MIXED_EXT ALLOCATED 0_PCT_FULL DIFF (<span>1</span>:<span>6</span>) <span>=</span><span> CHANGED
ML (</span><span>1</span>:<span>7</span>) <span>=</span> <span>NOT</span><span> MIN_LOGGED

Slot </span><span>0</span> Offset <span>0x60</span> Length <span>77</span><span>

Record Type </span><span>=</span> PRIMARY_RECORD Record Attributes <span>=</span> NULL_BITMAP Record Size <span>=</span> <span>77</span><span>

Memory </span><span>Dump</span> <span>@0x000000000DC7A060</span>

<span>0000000000000000</span>: <span>10004900</span> <span>00000300</span> <span>00000000</span> <span>01000003</span><span> †..I............. 
</span><span>0000000000000010</span>: <span>00000000</span> <span>00000000</span> 0001001f <span>00000001</span><span> †................ 
</span><span>0000000000000020</span>: <span>00570000</span> <span>00010056</span> <span>00000001</span><span> 000b0000 †.W.....V........ 
</span><span>0000000000000030</span>: <span>00000000</span> <span>00090000</span> <span>00000000</span> <span>00110000</span><span> †.....    .......... 
</span><span>0000000000000040</span>: <span>00000000</span> <span>00010000</span> 000c0000 <span>00</span><span>††††††††.............

Slot </span><span>0</span> <span>Column</span> <span>1</span> Offset <span>0x4</span> Length <span>8</span> Length (physical) <span>8</span><span>

auid </span><span>=</span> <span>196608</span><span>

Slot </span><span>0</span> <span>Column</span> <span>2</span> Offset <span>0xc</span> Length <span>1</span> Length (physical) <span>1</span><span>

type </span><span>=</span> <span>1</span><span>

Slot </span><span>0</span> <span>Column</span> <span>3</span> Offset <span>0xd</span> Length <span>8</span> Length (physical) <span>8</span><span>

ownerid </span><span>=</span> <span>196608</span><span>

Slot </span><span>0</span> <span>Column</span> <span>4</span> Offset <span>0x15</span> Length <span>4</span> Length (physical) <span>4</span><span>

status </span><span>=</span> <span>0</span><span>

Slot </span><span>0</span> <span>Column</span> <span>5</span> Offset <span>0x19</span> Length <span>2</span> Length (physical) <span>2</span><span>

fgid </span><span>=</span> <span>1</span><span>

pgfirst </span><span>=</span> <span>[</span><span>Binary data</span><span>]</span> Slot <span>0</span> <span>Column</span> <span>6</span> Offset <span>0x1b</span> Length <span>6</span> Length (physical) <span>6</span><span>

pgfirst </span><span>=</span> <span>0x1f0000000100</span><span>

pgroot </span><span>=</span> <span>[</span><span>Binary data</span><span>]</span> Slot <span>0</span> <span>Column</span> <span>7</span> Offset <span>0x21</span> Length <span>6</span> Length (physical) <span>6</span><span>

pgroot </span><span>=</span> <span>0x570000000100</span><span>

pgfirstiam </span><span>=</span> <span>[</span><span>Binary data</span><span>]</span> Slot <span>0</span> <span>Column</span> <span>8</span> Offset <span>0x27</span> Length <span>6</span> Length (physical) <span>6</span><span>

pgfirstiam </span><span>=</span> <span>0x560000000100</span><span>

Slot </span><span>0</span> <span>Column</span> <span>9</span> Offset <span>0x2d</span> Length <span>8</span> Length (physical) <span>8</span><span>

pcused </span><span>=</span> <span>11</span><span>

Slot </span><span>0</span> <span>Column</span> <span>10</span> Offset <span>0x35</span> Length <span>8</span> Length (physical) <span>8</span><span>

pcdata </span><span>=</span> <span>9</span><span>

Slot </span><span>0</span> <span>Column</span> <span>11</span> Offset <span>0x3d</span> Length <span>8</span> Length (physical) <span>8</span><span>

pcreserved </span><span>=</span> <span>17</span><span>

Slot </span><span>0</span> <span>Column</span> <span>12</span> Offset <span>0x45</span> Length <span>4</span> Length (physical) <span>4</span><span>

dbfragid </span><span>=</span> <span>1</span><span>

Slot </span><span>0</span> Offset <span>0x0</span> Length <span>0</span> Length (physical) <span>0</span><span>

KeyHashValue </span><span>=</span> (016862d84319)
ログイン後にコピー

 

SELECT COUNT(*) FROM sys.[allocation_units]
--131
SELECT * FROM sys.[allocation_units]
SELECT * FROM sys.[system_internals_allocation_units]

 

存储在数据库1:16页面上(是[sys.system_internals_allocation_units]系统表)《深入解析sql2008》

 

第十七篇完

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート