欢迎访问 生活随笔!

ag凯发k8国际

当前位置: ag凯发k8国际 > 运维知识 > 数据库 >内容正文

数据库

无ldf文件情况下恢复数据库数据纪实 -ag凯发k8国际

发布时间:2024/10/8 数据库 0 豆豆
ag凯发k8国际 收集整理的这篇文章主要介绍了 无ldf文件情况下恢复数据库数据纪实 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

前几天,我采用分离数据库的办法,清理了某moss站点对应的数据库日志(日志文件膨胀的太快了,正确的做法用压缩)。

我发现moss某站点对应的数据库挂掉了。尽管之前我备份了完整的mdf和ldf文件,放在data目录下,重新放回去,sql管理器中只能看到这个数据库的图标,无法展开看到表等等。

环境:

moss2007、ms sql2005、windows2003
详细的恢复过程如下:
问题描述:
估计是sql server 2005数据库日志文件可能会发生损坏,例如硬件故障、计算机非正常重启或关机等等。
先后出现的症状如下:
1、在sql server management studio中显示数据库处于置疑(suspect)状态,无法展开数据库的树形结构(我在今天恢复的时候连这个状态都没有,只有个图标,跟上周在addison座位上看到的症状一样)。
2、事件日志可能会出现如下错误信息:
could not redo log record (21737:686:9), for transaction id (0:2334886), on page (1:37527), database ”test” (database id 15). page: lsn = (21735:299:5), type = 2. log: opcode = 3, context 19, prevpagelsn: (21737:615:1). restore from a backup of the database, or repair the database.
during redoing of a logged operation in database ”test”, an error occurred at log record id (76116:286:2). typically, the specific failure is previously logged as an error in the windows event log service. restore the database from a full backup, or repair the database.
3、无法分离数据库
4、用create database dbname on ( filename = n”dbfile” ) for attach_rebuild_log附加数据库时出现提示:the log cannot be rebuilt because the database was not cleanly shut down.
恢复步骤:
1、停止数据库服务。
2、将需要恢复的数据库文件复制到另外的位置。
3、启动数据库服务。
4、确认要恢复的数据库文件已经成功复制到另外的位置,然后在sql server management studio中删除要恢复的数据库。
5、新建同名的数据库(数据库文件名也要相同)。
6、停止数据库服务。
7、用第2步中备份的.mdf文件覆盖新数据库的同名文件。
8、启动数据库服务。
9、运行alter database dbname set emergency,将数据库设置为emergency mode
10、运行下面的命令就可以恢复数据库(名称是wss_content)(我是依次执行的):

 

代码  1--置数据库与紧急状态
 2alter database wss_content set emergency 
 3--允许对系统目录进行即席更新
 4sp_configure 'allow updates', 1 
 5go 
 6reconfigure with override 
 7go 
 8--单一用户模式
 9sp_dboption 'wss_content', 'single user', 'true'
10--创建此数据库对应的日志文件
11dbcc checkdb(wss_content,repair_allow_data_loss)
12--之后可以执行多用于模式的命令
13dbcc checkdb(wss_content,repair_rebuild)
14--多用户模式
15exec sp_dboption 'wss_content', 'single user', 'false'
16--禁止对系统目录进行即席更新
17sp_configure 'allow updates', 0 
18go 
19reconfigure with override 
20

注意网上很多关于sql2000的做法,其中创建日志的命令dbcc rebuild_log在sql2005中无效。

总结:估计此数据库的日志文件记录了错误的信息。看来日志我们要恰当的利用。

转载于:https://www.cnblogs.com/mingle/archive/2009/11/30/1613952.html

总结

以上是ag凯发k8国际为你收集整理的无ldf文件情况下恢复数据库数据纪实的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得ag凯发k8国际网站内容还不错,欢迎将ag凯发k8国际推荐给好友。

  • 上一篇:
  • 下一篇:
网站地图