Skip to content

Commit b88100f

Browse files
BrentOzarclaude
andcommitted
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 BrentOzarULTD#3960 applied to CheckId 14. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 69ffdd0 commit b88100f

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

sp_BlitzBackups.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -975,18 +975,18 @@ RAISERROR('Rules analysis starting', 0, 1) WITH NOWAIT;
975975
100 AS [Priority],
976976
b.database_name AS [Database Name],
977977
''No CHECKSUMS'' AS [Finding],
978-
''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]
978+
''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]
979979
FROM ' + QUOTENAME(@MSDBName) + N'.dbo.backupset AS b
980980
WHERE b.has_backup_checksums = 0
981-
AND b.backup_finish_date >= DATEADD(DAY, -30, SYSDATETIME())
981+
AND b.backup_finish_date >= @StartTime
982982
GROUP BY b.database_name;' + @crlf;
983983

984984
IF @Debug = 1
985985
PRINT @StringToExecute;
986986

987987
INSERT #Warnings ( CheckId, Priority, DatabaseName, Finding, Warning )
988-
EXEC sys.sp_executesql @StringToExecute;
989-
988+
EXEC sys.sp_executesql @StringToExecute, N'@StartTime DATETIME2', @StartTime;
989+
990990
/*Damaged is a Black Flag album. You don''t want your backups to be like a Black Flag album. */
991991

992992
SET @StringToExecute = N'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;' + @crlf;
@@ -1089,17 +1089,17 @@ IF @ProductVersionMajor >= 12
10891089
100 AS [Priority],
10901090
b.database_name AS [Database Name],
10911091
''Uncompressed backups'' AS [Finding],
1092-
''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]
1092+
''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]
10931093
FROM ' + QUOTENAME(@MSDBName) + '.dbo.backupset AS b
10941094
WHERE backup_size = compressed_backup_size AND type = ''D''
1095-
AND b.backup_finish_date >= DATEADD(DAY, -30, SYSDATETIME())
1095+
AND b.backup_finish_date >= @StartTime
10961096
GROUP BY b.database_name;' + @crlf;
10971097

10981098
IF @Debug = 1
10991099
PRINT @StringToExecute;
11001100

11011101
INSERT #Warnings ( CheckId, Priority, DatabaseName, Finding, Warning )
1102-
EXEC sys.sp_executesql @StringToExecute;
1102+
EXEC sys.sp_executesql @StringToExecute, N'@StartTime DATETIME2', @StartTime;
11031103

11041104
/*Looking for backups directed at the NUL device.*/
11051105
SET @StringToExecute =N'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;' + @crlf;

0 commit comments

Comments
 (0)