Retreiving Backup file details in SQL Server

Sometimes we want to view the information of a backup file that was taken earlier. Below query returns the records of all the backup files that are older than 30 days.

SELECT
    CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server
  , B.database_name
  , B.backup_start_date
  , B.backup_finish_date
  , B.user_name
  , CASE B.type
      WHEN 'D' THEN 'Database'
      WHEN 'L' THEN 'Log'
      WHEN 'I' THEN 'Differential database'
      WHEN 'F' THEN 'File or filegroup'
      WHEN 'G' THEN 'Differential file'
      WHEN 'P' THEN 'Partial'
      WHEN 'Q' THEN 'Differential partial'
    END AS backup_type
  , B.server_name 
  , B.machine_name 
  , B.backup_size
  , A.physical_device_name
  , B.name AS backupset_name
FROM msdb.dbo.backupmediafamily A
JOIN msdb.dbo.backupset B 
  ON A.media_set_id = B.media_set_id
WHERE (CONVERT(datetime, B.backup_start_date, 102) >= GETDATE() - 7)
ORDER BY
B.backup_finish_date DESC
  • Recent Posts

    • 652,102 hits
  • Join 43 other subscribers
  • Archives

  • Categories

  • April 2024
    M T W T F S S
    1234567
    891011121314
    15161718192021
    22232425262728
    2930