sp_BlitzBackups: use @StartTime for CheckId 7 and 12#3962
Merged
Conversation
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) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates sp_BlitzBackups so CheckId 7 (No CHECKSUMS) and CheckId 12 (Uncompressed backups) honor the procedure’s dynamic lookback window by filtering on @StartTime (derived from @HoursBack) instead of a hard-coded 30-day window.
Changes:
- Replace
DATEADD(DAY, -30, SYSDATETIME())filters with@StartTimefor CheckId 7 and 12. - Pass
@StartTimeinto the dynamic SQL viasp_executesqlparameters to avoid undeclared-variable failures. - Remove “last/past 30 days” wording from the warning strings.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DATEADD(DAY, -30, SYSDATETIME()), ignoring the user's@HoursBackparameter.@StartTime(already used elsewhere in this proc), pass@StartTimethroughsp_executesql, and drop the "in the last 30 days" / "in the past 30 days" wording from the warning text now that the window is dynamic.DATEADD(YEAR, -1, @StartTime)) is intentional and left alone — it backs the 13-column month pivot.Test plan
EXEC sp_BlitzBackups @HoursBack = 24, @Debug = 1;— confirm CheckId 7/12 dynamic SQL prints@StartTime(noDATEADD(DAY, -30, ...)) and runs without "Must declare the scalar variable @starttime".EXEC sp_BlitzBackups @HoursBack = 168, @Debug = 1;— same.EXEC sp_BlitzBackups @HoursBack = 720, @Debug = 1;— verify CheckId 7/12 row counts grow vs.@HoursBack = 24, proving the parameter is now honored.🤖 Generated with Claude Code