检索有关备份和还原操作的信息
要获取在当前数据库实例上执行的所有备份操作的列表:
SELECT sdb.Name AS DatabaseName,
COALESCE(CONVERT(VARCHAR(50), bus.backup_finish_date, 120),'-') AS LastBackUpDateTime
FROM sys.sysdatabases sdb
LEFT OUTER JOIN msdb.dbo.backupset bus ON bus.database_name = sdb.name
ORDER BY sdb.name, bus.backup_finish_date DESC
要获取在当前数据库实例上执行的所有还原操作的列表:
SELECT
[d].[name] AS database_name,
[r].restore_date AS last_restore_date,
[r].[user_name],
[bs].[backup_finish_date] AS backup_creation_date,
[bmf].[physical_device_name] AS [backup_file_used_for_restore]
FROM master.sys.databases [d]
LEFT OUTER JOIN msdb.dbo.[restorehistory] r ON r.[destination_database_name] = d.Name
INNER JOIN msdb.dbo.backupset [bs] ON [r].[backup_set_id] = [bs].[backup_set_id]
INNER JOIN msdb.dbo.backupmediafamily bmf ON [bs].[media_set_id] = [bmf].[media_set_id]
ORDER BY [d].[name], [r].restore_date DESC