SELECT TOP 100 bs.server_name
,bs.database_name
,bs.recovery_model
,convert(NUMERIC(10, 2), bs.backup_size / 1024 / 1024) [backup, Mb]
,bs.compressed_backup_size
,bs.backup_start_date
,bs.backup_finish_date
,datediff(ss, bs.backup_start_date, bs.backup_finish_date) [Duration (sec)]
,bs.name
,bs.user_name
,CASE bs.type
WHEN 'D'
THEN 'Database full'
WHEN 'I'
THEN 'Database Differential'
WHEN 'L'
THEN 'Log'
WHEN 'F'
THEN 'File or Filegroup'
WHEN 'G'
THEN 'File Differential'
WHEN 'P'
THEN 'Partial'
WHEN 'Q'
THEN 'Partial Differential'
ELSE 'Unknown'
END 'backup type' -- from BOL
,bmf.media_set_id
,bmf.physical_device_name
FROM msdb.dbo.backupset bs
INNER JOIN msdb.dbo.backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
WHERE bs.database_name = 'DB'
ORDER BY backup_finish_date DESC
数据库 msdb 中有一个名为 dbo.backupmediafamily 的表。它包含 physical_device_name 列,可以正确更新。
使用以下脚本,您可以获取数据库 DB 的最后 100 个注册备份的列表: