Query MSDB for backup history and database restore file details

I can't say enough good things about sp_RestoreGene


So much so that I used it to generate all my syntax for a nightly refresh process using Full and Diff backups from production to another server of nearly 250 databases consisting of 2tb of data.  I will cover this solution in another blog post.  The creator of sp_RestoreGene looks and takes in feedback from their website and based upon some of my feedback and suggestions for enhancement they were later implemented.  Today the variable @ExcludeDiffAndLogBackups was updated so that the value changed from data type bit to int
  
This allowed for the existing BIT data type functionality to be retained and extended it offering by allowing for new values 2 and 3 where 0 (default) = full, diff and logs and   1 = full only where previously the only  excepted values.  Now values  2 = full and diff,    3 = full and logs can be used.

Prior to using this stored procedure I found myself referring to the below syntax from SQL Server Management Studio (SSMS) or using Idera SQL Safe or RedGate SQL Backup.

-- Get Backup History for database selected in SSMS window
DECLARE @CURRENTDB VARCHAR(128);
SET @CURRENTDB = DB_NAME();

SELECT TOP 100 s.database_name, m.physical_device_name,
       CAST(CAST(s.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize,
       CAST(DATEDIFF(second, s.backup_start_date, s.backup_finish_date) AS VARCHAR(4)) + ' ' + 'Seconds' TimeTaken,
       s.backup_start_date, CAST(s.first_lsn AS VARCHAR(50)) AS first_lsn, CAST(s.last_lsn AS VARCHAR(50)) AS last_lsn,
       CASE s.[type]
            WHEN 'D' THEN 'Full'
            WHEN 'I' THEN 'Differential'
            WHEN 'L' THEN 'Transaction Log' END AS BackupType, s.server_name, s.recovery_model
  FROM msdb.dbo.backupset s
      INNER JOIN msdb.dbo.backupmediafamily m ON s.media_set_id = m.media_set_id
 WHERE s.database_name = @CURRENTDB -- Remove this line for all the database
 ORDER BY backup_start_date DESC, backup_finish_date;
GO

Comments

Popular posts from this blog

How to mass update all or some sql server agent job step commands

SQL Monitoring for Blocking and Locking Capture and Log to table with sp_WhoIsActive or sp_BlitzWho

SQL Server General Index Naming Convention