我在创建备份时进行了描述。
我可以检索有关我的备份的信息:
SELECT name, database_name, description, backup_start_date FROM msdb.dbo.backupset
我可以使用说明和/或备份创建日期按脚本还原数据库吗?
我需要类似的东西:
RESTORE DATABASE [MyDB] FROM DISK = N'D:\dbbackups\ByDB.bak'
Where Description = 'SomeDescr' and Date = '10.05.2016'
答案 0 :(得分:0)
我找到了一种方法
declare @Position int = 0;
SELECT @Position = position
FROM msdb.dbo.backupset
where database_name = 'MyDB'
and type = 'I' and Description = 'some description'
print @Position
ALTER DATABASE [myDB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [myDB] FROM DISK = N'D:\dbbackups\myDB.bak' WITH FILE = 1, NORECOVERY, NOUNLOAD, REPLACE, STATS = 5
RESTORE DATABASE [myDB] FROM DISK = N'D:\dbbackups\myDB.bak' WITH FILE = @Position, NOUNLOAD, STATS = 5