What is the last and latest RESTORED backup file (FULL/DIFF/LOG)

SQL Script
SELECT
    rh.restore_date AS [RestoreTime],
    rh.destination_database_name AS [Database],
    CASE rh.restore_type
        WHEN 'D' THEN 'Full Database'
        WHEN 'I' THEN 'Differential'
        WHEN 'L' THEN 'Log'
        WHEN 'F' THEN 'File'
        WHEN 'G' THEN 'Filegroup'
        WHEN 'P' THEN 'Partial'
        WHEN 'V' THEN 'VerifyOnly'
    END AS [RestoreType],
    bs.backup_start_date AS [BackupMadeAt],
    bmf.physical_device_name AS [SourceFile],
    rh.user_name AS [RestoredBy]
FROM msdb.dbo.restorehistory rh
INNER JOIN msdb.dbo.backupset bs 
    ON rh.backup_set_id = bs.backup_set_id
INNER JOIN msdb.dbo.backupmediafamily bmf 
    ON bs.media_set_id = bmf.media_set_id
WHERE rh.destination_database_name = 'dbname' -- Change this
ORDER BY rh.restore_date DESC;

Comments

Popular posts from this blog

Always On FailOver Events

SSAS Cube or Database backup with Powershell command "Backup-AsDatabase"

AG SECONDARY DATABASE "Synchronizing" Query