使用Log Explorer查看和恢复数据 Log Explorer 4.1.可用于SQL Server2005的日志查看工具下载地址: http://download.csdn.net/source/620271使用方法:打开Log Explorer -> Attach Log File -> 选择SQL Server服务器和登陆方式 -> Connect -> 在Database Name中选择数据库 -> Attach-> 左面对话框中Browse-> View Log-> 就可以看到log记录了 想恢复的话: 右键Log记录 Undo Transation-> 选择保存文件名和路径-> 然后打开该文件到查询分析器里执行 T-sql代码就可以了 例如 如果Log是delete table where ...的话,生成的文件代码就是insert table .... 然后将此insert table的代码放到查询分析器里执行.就可以恢复数据. ---------------------------------------------------------------------- --如何恢复被delete/update的数据 ---------------------------------------------------------------------- 1 连接到被删除数据库的Db 打开log explorer 选择 "file"->"attach log file"->选择服务器和登陆方式->"connect"->选择"数据库"->"attach" 2 查看日志 在左面操作项目的对话框中选择"browse"项目->"view log"->就可以看到当前的Log记录了 3 恢复数据 右键某一条log记录,选择"undo transation"->"选择保存文件名和路径"->然后打开该文件到查询分析器里执行 T-sql代码就可以了 例如: 如果log是delete table where ...的话,生成的文件代码就是insert table .... ---------------------------------------------------------------------- --Log Explorer恢复被drop table和truncate table后的数据 ---------------------------------------------------------------------- 1 连接到被删除数据库的Db 操作同上 2 恢复方法 1) 选择"salvaage dropped/truncate"菜单,在右边的对话框中选择表名,和droped/trucated的日期, File Name中选择生成insert语句脚步的存放位置,condition选择是droped还是truncated, 最后点击"create" 就会生成insert语句,把生成的语句到查询分析器里面执行一下就可以了 2) 选择"ViewDDL Commands"菜单->选"truncate table" 操作项->点击"Salvage"->生成语句->查询分析器里执行 ---------------------------------------------------------------------- --log explorer使用的几个问题 ---------------------------------------------------------------------- 1) 对数据库做完全/差异/日志备份 备份时如果选用了删除事务日志中不活动的条目 再用Log explorer打试图看日志时,提示No log recorders found that match the filter,would you like to view unfiltered data 选择yes 就看不到刚才的记录了如果不选用了删除事务日志中不活动的条目 再用Log explorer打试图看日志时,就能看到原来的日志并做恢复 2) 修改了其中一个表中的部分数据,此时用Log explorer看日志,可以作日志恢复 3) 然后恢复备份,(注意:恢复是断开log explorer与数据库的连接,或连接到其他数据上, 否则会出现数据库正在使用无法恢复) 恢复完后,再打开log explorer 提示No log recorders found that match the filter,would you like to view unfiltered data,选择yes 就看不到刚才在2中修改的日志记录,所以无法做恢复. 4) 不要用SQL的备份功能备份,搞不好你的日志就破坏了.正确的备份方法是: 停止SQL服务,复制数据文件及日志文件进行文件备份.然后启动SQL服务,用log explorer恢复数据
看ERRORLOG信息,在C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Log2011-04-10 09:13:02.24 备份 Database backed up. Database: ReportServer, creation date(time): 2011/03/13(10:02:11), pages dumped: 372, first LSN: 41:99:37, last LSN: 41:117:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'D:\ts'}). This is an informational message only. No user action is required. 2011-04-10 09:14:25.59 spid53 Starting up database 'xxx'. 2011-04-10 09:14:25.66 spid53 The database 'xxx' is ed RESTORING and is in a state that does not allow recovery to be run. 2011-04-10 09:14:25.95 spid53 Starting up database 'xxx'. 2011-04-10 09:14:26.33 备份 Restore is complete on database 'xxx'. The database is now available. 2011-04-10 09:14:26.33 备份 Database was restored: Database: xxx, creation date(time): 2011/03/13(10:02:11), first LSN: 41:99:37, last LSN: 41:117:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'D:\ts'}). Informational message. No user action required.
--查看数据库还原记录 SELECT rh.destination_database_name, rh.restore_date, CASE WHEN rf.file_number = 1 THEN 'datafile' WHEN rf.file_number = 2 THEN 'logfile' ELSE 'elsefile' END AS dbfile, CASE WHEN rh.restore_type = 'D' THEN 'Database' WHEN rh.restore_type = 'F' THEN 'File' WHEN rh.restore_type = 'G' THEN 'Filegroup' WHEN rh.restore_type = 'I' THEN 'Differential' WHEN rh.restore_type = 'L' THEN 'Log' WHEN rh.restore_type = 'V' THEN 'Verifyonly' WHEN rh.restore_type = 'R' THEN 'Revert' END AS c, Isnull(rf.destination_phys_drive, '') destination_phys_drive, rf.destination_phys_name FROM msdb.dbo.restorehistory rh JOIN msdb.dbo.restorefile rf ON rh.restore_history_id = rf.restore_history_id WHERE rh.destination_database_name = 'dbname' --by claro 201104101800 @xi'an
http://download.csdn.net/source/620271使用方法:打开Log Explorer -> Attach Log File -> 选择SQL Server服务器和登陆方式 -> Connect ->
在Database Name中选择数据库 -> Attach-> 左面对话框中Browse-> View Log-> 就可以看到log记录了 想恢复的话: 右键Log记录 Undo Transation-> 选择保存文件名和路径-> 然后打开该文件到查询分析器里执行
T-sql代码就可以了 例如 如果Log是delete table where ...的话,生成的文件代码就是insert table ....
然后将此insert table的代码放到查询分析器里执行.就可以恢复数据.
----------------------------------------------------------------------
--如何恢复被delete/update的数据
----------------------------------------------------------------------
1 连接到被删除数据库的Db
打开log explorer 选择 "file"->"attach log file"->选择服务器和登陆方式->"connect"->选择"数据库"->"attach"
2 查看日志
在左面操作项目的对话框中选择"browse"项目->"view log"->就可以看到当前的Log记录了
3 恢复数据
右键某一条log记录,选择"undo transation"->"选择保存文件名和路径"->然后打开该文件到查询分析器里执行
T-sql代码就可以了
例如: 如果log是delete table where ...的话,生成的文件代码就是insert table ....
----------------------------------------------------------------------
--Log Explorer恢复被drop table和truncate table后的数据
----------------------------------------------------------------------
1 连接到被删除数据库的Db
操作同上
2 恢复方法
1) 选择"salvaage dropped/truncate"菜单,在右边的对话框中选择表名,和droped/trucated的日期,
File Name中选择生成insert语句脚步的存放位置,condition选择是droped还是truncated,
最后点击"create" 就会生成insert语句,把生成的语句到查询分析器里面执行一下就可以了
2) 选择"ViewDDL Commands"菜单->选"truncate table" 操作项->点击"Salvage"->生成语句->查询分析器里执行
----------------------------------------------------------------------
--log explorer使用的几个问题
----------------------------------------------------------------------
1) 对数据库做完全/差异/日志备份
备份时如果选用了删除事务日志中不活动的条目
再用Log explorer打试图看日志时,提示No log recorders found that match the filter,would you like to view unfiltered data 选择yes 就看不到刚才的记录了如果不选用了删除事务日志中不活动的条目
再用Log explorer打试图看日志时,就能看到原来的日志并做恢复
2) 修改了其中一个表中的部分数据,此时用Log explorer看日志,可以作日志恢复
3) 然后恢复备份,(注意:恢复是断开log explorer与数据库的连接,或连接到其他数据上,
否则会出现数据库正在使用无法恢复)
恢复完后,再打开log explorer 提示No log recorders found that match the filter,would you like to view unfiltered data,选择yes 就看不到刚才在2中修改的日志记录,所以无法做恢复.
4) 不要用SQL的备份功能备份,搞不好你的日志就破坏了.正确的备份方法是:
停止SQL服务,复制数据文件及日志文件进行文件备份.然后启动SQL服务,用log explorer恢复数据
2011-04-10 09:14:25.59 spid53 Starting up database 'xxx'.
2011-04-10 09:14:25.66 spid53 The database 'xxx' is ed RESTORING and is in a state that does not allow recovery to be run.
2011-04-10 09:14:25.95 spid53 Starting up database 'xxx'.
2011-04-10 09:14:26.33 备份 Restore is complete on database 'xxx'. The database is now available.
2011-04-10 09:14:26.33 备份 Database was restored: Database: xxx, creation date(time): 2011/03/13(10:02:11), first LSN: 41:99:37, last LSN: 41:117:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'D:\ts'}). Informational message. No user action required.
SELECT rh.destination_database_name,
rh.restore_date,
CASE
WHEN rf.file_number = 1 THEN 'datafile'
WHEN rf.file_number = 2 THEN 'logfile'
ELSE 'elsefile'
END AS dbfile,
CASE
WHEN rh.restore_type = 'D' THEN 'Database'
WHEN rh.restore_type = 'F' THEN 'File'
WHEN rh.restore_type = 'G' THEN 'Filegroup'
WHEN rh.restore_type = 'I' THEN 'Differential'
WHEN rh.restore_type = 'L' THEN 'Log'
WHEN rh.restore_type = 'V' THEN 'Verifyonly'
WHEN rh.restore_type = 'R' THEN 'Revert'
END AS c,
Isnull(rf.destination_phys_drive, '') destination_phys_drive,
rf.destination_phys_name
FROM msdb.dbo.restorehistory rh
JOIN msdb.dbo.restorefile rf
ON rh.restore_history_id = rf.restore_history_id
WHERE rh.destination_database_name = 'dbname' --by claro 201104101800 @xi'an