From b88100ff47a54acfdb936e797a653910299e338c Mon Sep 17 00:00:00 2001 From: Brent Ozar Date: Sun, 26 Apr 2026 14:51:11 +0100 Subject: [PATCH] sp_BlitzBackups: use @StartTime for CheckId 7 and 12 The "No CHECKSUMS" (CheckId 7) and "Uncompressed backups" (CheckId 12) checks were filtering on a hard-coded 30-day window via DATEADD(DAY, -30, SYSDATETIME()) instead of the user-supplied @HoursBack window already exposed via @StartTime. That ignored @HoursBack and made the warning text inconsistent with the actual window being analyzed. Replace both filters with @StartTime, pass @StartTime through sp_executesql, and drop the "in the last 30 days" / "in the past 30 days" wording from the findings now that the window is dynamic. Same treatment as PR #3960 applied to CheckId 14. Co-Authored-By: Claude Opus 4.7 (1M context) --- sp_BlitzBackups.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sp_BlitzBackups.sql b/sp_BlitzBackups.sql index 5d3d18ab..0fcd35aa 100755 --- a/sp_BlitzBackups.sql +++ b/sp_BlitzBackups.sql @@ -975,18 +975,18 @@ RAISERROR('Rules analysis starting', 0, 1) WITH NOWAIT; 100 AS [Priority], b.database_name AS [Database Name], ''No CHECKSUMS'' AS [Finding], - ''The database '' + QUOTENAME(b.database_name) + '' has been backed up '' + CONVERT(VARCHAR(10), COUNT(*)) + '' times without CHECKSUMS in the past 30 days. CHECKSUMS can help alert you to corruption errors.'' AS [Warning] + ''The database '' + QUOTENAME(b.database_name) + '' has been backed up '' + CONVERT(VARCHAR(10), COUNT(*)) + '' times without CHECKSUMS. CHECKSUMS can help alert you to corruption errors.'' AS [Warning] FROM ' + QUOTENAME(@MSDBName) + N'.dbo.backupset AS b WHERE b.has_backup_checksums = 0 - AND b.backup_finish_date >= DATEADD(DAY, -30, SYSDATETIME()) + AND b.backup_finish_date >= @StartTime GROUP BY b.database_name;' + @crlf; IF @Debug = 1 PRINT @StringToExecute; INSERT #Warnings ( CheckId, Priority, DatabaseName, Finding, Warning ) - EXEC sys.sp_executesql @StringToExecute; - + EXEC sys.sp_executesql @StringToExecute, N'@StartTime DATETIME2', @StartTime; + /*Damaged is a Black Flag album. You don''t want your backups to be like a Black Flag album. */ SET @StringToExecute = N'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;' + @crlf; @@ -1089,17 +1089,17 @@ IF @ProductVersionMajor >= 12 100 AS [Priority], b.database_name AS [Database Name], ''Uncompressed backups'' AS [Finding], - ''The database '' + QUOTENAME(b.database_name) + '' has had '' + CONVERT(VARCHAR(10), COUNT(*)) + '' uncompressed backups in the last 30 days. This is a free way to save time and space. And SPACETIME. If your version of SQL supports it.'' AS [Warning] + ''The database '' + QUOTENAME(b.database_name) + '' has had '' + CONVERT(VARCHAR(10), COUNT(*)) + '' uncompressed backups. This is a free way to save time and space. And SPACETIME. If your version of SQL supports it.'' AS [Warning] FROM ' + QUOTENAME(@MSDBName) + '.dbo.backupset AS b WHERE backup_size = compressed_backup_size AND type = ''D'' - AND b.backup_finish_date >= DATEADD(DAY, -30, SYSDATETIME()) + AND b.backup_finish_date >= @StartTime GROUP BY b.database_name;' + @crlf; IF @Debug = 1 PRINT @StringToExecute; INSERT #Warnings ( CheckId, Priority, DatabaseName, Finding, Warning ) - EXEC sys.sp_executesql @StringToExecute; + EXEC sys.sp_executesql @StringToExecute, N'@StartTime DATETIME2', @StartTime; /*Looking for backups directed at the NUL device.*/ SET @StringToExecute =N'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;' + @crlf;