如何通过trn日志文件恢复SQL Server
首先恢复时一个完整的备份,但在完整的备份里一定要选择with nonerecovery(企业管理器里选项中是第2项)
sql 语句是
restore database mydata from disk = 'c:\temp\movedb.bak' with norecovery
这时数据库就会变成恢复模式,这样你就可以一条一条的把trn文件添加进行恢复了.
语句是
restore log Mydata from disk =
"D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\data\data_tlog_200407290022.TRN"
with norecovery
当你恢复到你想要的数据时,再把数据库变成正常的模式就可以.
语句为
restore log Mydata from disk =
"D:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\data\data_tlog_200407290022.TRN"
with recovery
这样就可以在你的备用的机器上把数据恢复到某个时间点了.
/* 下面使用游标示例 */
declare @pathname varchar(200)
DECLARE vendor_cursor CURSOR FOR SELECT 'D:\xx备份\testaa - 复制\'+ttttt FROM test
OPEN vendor_cursor
FETCH NEXT FROM vendor_cursor INTO @pathname
WHILE @@FETCH_STATUS = 0
BEGIN
restore log Mydata from disk = @pathname with norecovery
FETCH NEXT FROM vendor_cursor INTO @pathname
END
CLOSE vendor_cursor