Skip to content

sp_BlitzBackups: use @StartTime for CheckId 7 and 12#3962

Merged
BrentOzar merged 1 commit intodevfrom
sp_BlitzBackups-StartTime-CheckId-7-12
Apr 26, 2026
Merged

sp_BlitzBackups: use @StartTime for CheckId 7 and 12#3962
BrentOzar merged 1 commit intodevfrom
sp_BlitzBackups-StartTime-CheckId-7-12

Conversation

@BrentOzar
Copy link
Copy Markdown
Member

Summary

  • CheckId 7 (No CHECKSUMS) and CheckId 12 (Uncompressed backups) were filtering on a hard-coded 30-day window via DATEADD(DAY, -30, SYSDATETIME()), ignoring the user's @HoursBack parameter.
  • Replace both filters with @StartTime (already used elsewhere in this proc), pass @StartTime through sp_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.
  • Same treatment as for #3959 - added check for backup to NUL device #3960 applied to CheckId 14 (Backup to NUL device). Trending block at line 797 (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 (no DATEADD(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.
  • Confirm no result row for CheckId 7 or 12 contains the phrase "30 days".

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings April 26, 2026 13:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @StartTime for CheckId 7 and 12.
  • Pass @StartTime into the dynamic SQL via sp_executesql parameters 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.

Comment thread sp_BlitzBackups.sql
Comment thread sp_BlitzBackups.sql
@BrentOzar BrentOzar added this to the 2026-07 Release milestone Apr 26, 2026
@BrentOzar BrentOzar merged commit 9efb841 into dev Apr 26, 2026
4 checks passed
@BrentOzar BrentOzar deleted the sp_BlitzBackups-StartTime-CheckId-7-12 branch April 26, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants