从日志中恢复到时间点

来源:互联网 发布:淘宝自己组合关键词 编辑:程序博客网 时间:2024/05/16 15:07
<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>

Author:DavidEuler
Date:2004/10/16
Email:de_euler-david@yahoo.com.cn

有任何问题,请与我联系:)



       中可以使得数据库回复到指定的时间点,SQLServer数据库的RecoveryModel为full或者Bulkcopy的时候,是可以从日志来恢复数据库的。实际上日志中记录的一条一条的transactsql语句,恢复数据库的时候会redo这些sql语句。
  
前提条件:myBBS是数据库test中的一个表,

         数据库test的RecoveryModel为Full,AutoClose,AutoShrink两个选项未选中。

         数据库test的datafiles和logfiles均为默认的自动增长状态。



A:2004/10/13,16:00进行数据库备份,backupdatabasetesttodisk='d:/db/1600.bak'withinit

B:2004/10/14,13:00对数据库进行了update,delete等操作;

C:2004/10/15,18:00使用deletemybbswhereid>300时,语句误写成deletemybbs,因而删除了表mybbs中的所有数据。

 

现在在C点,C点对数据库进行了误操作,我们希望数据库能够恢复到C之前的状态,比如恢复到10月15日17:59分的状态。

要恢复数据库B点,使用的是A点备分的数据库1600.bak;而使用的日志备分是最新的备分1820.logs;因而进行如下操作:

 

--备分日志:

BACKUPLOGtestTODISK='d:/1820.logs'WITHINIT

 

--恢复数据库1600.bak,使用WITHNORECOVERY参数:

RESTOREDATABASEtestfromdisk='d:/db/1640.bak'WITHNORECOVERY

 

--使用日志恢复数据库到10月15日17:59分:

RESTORELOGtest
       FROMdisk='d:/1820.logs'WITHRECOVERY,STOPAT='10/15/200417:59'


 

上面的三条TransactSQL语句的对应过程:

     1.恢复数据库到A点;

     2.执行A-B之间的log记录,把数据库恢复到B点.

 

 

      这样就恢复数据库到了指定的时间点。如果恢复不成功,可能的原因是:1.未使用正确的备分数据库;2.数据库选项选中了AutoShrink.

 

 

 

<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>