通过日志恢复MS SQL数据案例

来源:互联网 发布:韦德12年总决赛数据 编辑:程序博客网 时间:2024/05/14 07:28
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
 

前提条件是数据库的故障恢复改为非简单模式,去掉自动关闭和自动收缩两个选项。

1、创建一个数据库test 创建时间为2006-11-18 09:40

2、对数据库进行备份,备份时间为2006-11-18 09:42

语句如下:

backup database test to disk='d:databasetest.bak' with init

提示:

已处理 216 页,这些页属于数据库 'test' 的文件 'test'(位于文件 1 上)。

已处理 1 页,这些页属于数据库 'test' 的文件 'test_log'(位于文件 1 上)。

BACKUP DATABASE 操作成功地处理了 217 页,花费了 0.191 秒(9.269 MB/秒)。

3、2006-11-18 09:44 对数据库进行操作删除和新增,我这边对客户资料进行删除和新增操作

原始的记录为

修改完后的记录为

下面开始还原操作

4、备分日志:现在时间是2006-11-18 09:47

语句如下:

BACKUP LOG test TO DISK='d:database11180947.logs' WITH INIT

提示:

已处理 4 页,这些页属于数据库 'test' 的文件 'test_log'(位于文件 1 上)。

BACKUP LOG 操作成功地处理了 4 页,花费了 0.104 秒(0.275 MB/秒)。

5、恢复之前数据库备份文件test.bak,使用WITH NORECOVERY参数:

RESTORE DATABASE test from disk='d:databasetest.bak' WITH NORECOVERY

提示:

已处理 216 页,这些页属于数据库 'test' 的文件 'test'(位于文件 1 上)。

已处理 1 页,这些页属于数据库 'test' 的文件 'test_log'(位于文件 1 上)。

RESTORE DATABASE 操作成功地处理了 217 页,花费了 0.352 秒(5.029 MB/秒)。

6、使用日志恢复数据库到时间为2006-11-18 09:43,即恢复09:44分的删除和新增操作

RESTORE LOG test FROM disk='d:database11180947.logs' WITH RECOVERY,STOPAT='11/18/2006 09:43'

提示:

已处理 4 页,这些页属于数据库 'test' 的文件 'test_log'(位于文件 1 上)。

RESTORE LOG 操作成功地处理了 4 页,花费了 0.016 秒(1.792 MB/秒)。

至此,再进入到软件中,可以看到,数据已经还原到原来的状态了

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击