Wednesday, September 17, 2025

Little script to see the backup history

 Today, I was teaching a co-worker how to create a copy only backup of a SQL Managed Instance database.  And I came up to use this script to verify the schedule on when a SQL Managed Instance is being backed up or how is MS doing it.

USE msdb;
GO
 
SELECT
    bs.database_name,
    bs.backup_start_date,
    bs.backup_finish_date,
    bs.type AS backup_type_code,
    CASE bs.type
        WHEN 'D' THEN 'Full Database'
        WHEN 'I' THEN 'Differential Database'
        WHEN 'L' THEN 'Transaction Log'
        ELSE 'Other'
    END AS backup_type,
    bs.backup_size / 1024 / 1024 AS backup_size_MB,
    bmf.physical_device_name,
    bs.name AS backup_set_name,
    bs.user_name
FROM
    dbo.backupset bs
INNER JOIN
    dbo.backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
WHERE
    bs.database_name = 'YourDatabaseName'  -- Replace with your actual database name
ORDER BY
    bs.backup_finish_date DESC;
 

No comments:

Post a Comment

Little script to see the backup history

 Today, I was teaching a co-worker how to create a copy only backup of a SQL Managed Instance database.  And I came up to use this script t...