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

解剖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》

 

第十七篇完

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
sqlserver数据库中已存在名为的对象怎么解决sqlserver数据库中已存在名为的对象怎么解决Apr 05, 2024 pm 09:42 PM

对于 SQL Server 数据库中已存在同名对象,需要采取以下步骤:确认对象类型(表、视图、存储过程)。如果对象为空,可使用 IF NOT EXISTS 跳过创建。如果对象有数据,使用不同名称或修改结构。使用 DROP 删除现有对象(谨慎操作,建议备份)。检查架构更改,确保没有引用删除或重命名的对象。

sqlserver服务无法启动怎么办sqlserver服务无法启动怎么办Apr 05, 2024 pm 10:00 PM

当 SQL Server 服务无法启动时,可采取以下步骤解决:检查错误日志以确定根本原因。确保服务帐户具有启动服务的权限。检查依赖项服务是否正在运行。禁用防病毒软件。修复 SQL Server 安装。如果修复不起作用,重新安装 SQL Server。

怎么查看sqlserver端口号怎么查看sqlserver端口号Apr 05, 2024 pm 09:57 PM

要查看 SQL Server 端口号:打开 SSMS,连接到服务器。在对象资源管理器中找到服务器名称,右键单击它,然后选择“属性”。在“连接”选项卡中,查看“TCP 端口”字段。

sqlserver数据库在哪里sqlserver数据库在哪里Apr 05, 2024 pm 08:21 PM

SQL Server 数据库文件通常存储在以下默认位置:Windows: C:\Program Files\Microsoft SQL Server\MSSQL\DATALinux: /var/opt/mssql/data可通过修改数据库文件路径设置来自定义数据库文件位置。

Java连接SqlServer错误如何解决Java连接SqlServer错误如何解决May 01, 2023 am 09:22 AM

问题发现这次使用的是SqlServer数据库,之前并没有使用过,但是问题不大,我按照需求文档的步骤连接好SqlServer之后,启动SpringBoot项目,发现了一个报错,如下:刚开始我以为是SqlServer连接问题呢,于是便去查看数据库,发现数据库一切正常,我首先第一时间问了我的同事,他们是否有这样的问题,发现他们并没有,于是我便开始了我最拿手的环节,面向百度编程。开始解决具体报错信息是这样,于是我便开始了百度报错:ERRORc.a.d.p.DruidDataSource$CreateCo

sqlserver英文安装怎么更改中文sqlserver英文安装怎么更改中文Apr 05, 2024 pm 10:21 PM

SQL Server 英文安装可通过以下步骤更改为中文:下载相应语言包;停止 SQL Server 服务;安装语言包;更改实例语言;更改用户界面语言;重启应用程序。

Win11无法安装SQL Server的原因及解决方案Win11无法安装SQL Server的原因及解决方案Dec 27, 2023 pm 07:48 PM

有网友反馈,在win11上无法安装sqlserver这款软件,不知道是怎么回事,根据目前的测试来看,win11存在硬盘问题,部分接口硬盘无法安装这款软件。win11为啥不能安装sqlserver:答:win11不能安装sqlserver是硬盘的问题。1、据了解,win11存在对于硬盘的检测bug。2、这导致sqlserver无法在“三星m.2接口”硬盘上安装。3、因此,如果我们要安装的话,需要准备一块其他硬盘。4、然后将该硬盘安装到电脑里,如果没有额外插槽的话就要换掉之前的硬盘。5、安装完成后,

sqlserver数据库日志怎么查询sqlserver数据库日志怎么查询Apr 05, 2024 pm 09:06 PM

可以通过以下步骤查询 SQL Server 数据库日志:1. 打开 SQL Server Management Studio,连接到数据库服务器;2. 展开“管理”节点,导航到“SQL Server 日志”;3. 选择要查询的日志文件,右键单击并选择“查看日志文件”;4. 浏览日志记录。其他查询日志方法:使用 Transact-SQL 查询、PowerShell Cmdlet。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.