Skip to content

Commit 409bcf4

Browse files
BrentOzarclaude
andcommitted
sp_BlitzBackups: use @starttime for NUL device check
Honor the @HoursBack parameter instead of a hard-coded 30-day window, matching the convention used elsewhere in this proc, and drop the "in the last 30 days" wording from the warning text now that the window is dynamic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0233d0f commit 409bcf4

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

sp_BlitzBackups.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,33 +1109,33 @@ IF @ProductVersionMajor >= 12
11091109
100 AS [Priority],
11101110
bs.database_name AS [Database Name],
11111111
''Backup to NUL device'' AS [Finding],
1112-
''The database '' + QUOTENAME(bs.database_name) + '' has had '' + CONVERT(VARCHAR(10), COUNT(*)) + '' backups to the NUL device in the last 30 days, the latest one being on ''+
1112+
''The database '' + QUOTENAME(bs.database_name) + '' has had '' + CONVERT(VARCHAR(10), COUNT(*)) + '' backups to the NUL device, the latest one being on ''+
11131113
CONVERT(NVARCHAR(25),MAX(bs.backup_finish_date),120)+''. These backups do not exist.'' AS [Warning]
11141114
FROM ' + QUOTENAME(@MSDBName) + '.dbo.backupset AS bs
11151115
INNER JOIN ' + QUOTENAME(@MSDBName) + '.dbo.backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
11161116
WHERE UPPER(bmf.physical_device_name)= N''NUL''
11171117
AND (bs.is_copy_only = 1 OR bs.recovery_model = N''SIMPLE'')
1118-
AND bs.backup_finish_date >= DATEADD(DAY, -30, SYSDATETIME())
1118+
AND bs.backup_finish_date >= @StartTime
11191119
GROUP BY bs.database_name' + @crlf;
1120-
SET @StringToExecute += N'UNION ALL' + @crlf + N'SELECT
1120+
SET @StringToExecute += N'UNION ALL' + @crlf + N'SELECT
11211121
14 AS CheckId,
11221122
100 AS [Priority],
11231123
bs.database_name AS [Database Name],
11241124
''Backup to NUL device without COPY_ONLY'' AS [Finding],
1125-
''The database '' + QUOTENAME(bs.database_name) + '' is not in SIMPLE recovery model and has had '' + CONVERT(VARCHAR(10), COUNT(*)) + '' backups to the NUL device in the last 30 days, the latest one being on ''+
1125+
''The database '' + QUOTENAME(bs.database_name) + '' is not in SIMPLE recovery model and has had '' + CONVERT(VARCHAR(10), COUNT(*)) + '' backups to the NUL device, the latest one being on ''+
11261126
CONVERT(NVARCHAR(25),MAX(bs.backup_finish_date),120)+''. These backups do not exist and they might mess up your current backup chain.'' AS [Warning]
11271127
FROM ' + QUOTENAME(@MSDBName) + '.dbo.backupset AS bs
11281128
INNER JOIN ' + QUOTENAME(@MSDBName) + '.dbo.backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
11291129
WHERE UPPER(bmf.physical_device_name)= N''NUL''
11301130
AND bs.is_copy_only = 0 AND bs.recovery_model <> N''SIMPLE''
1131-
AND bs.backup_finish_date >= DATEADD(DAY, -30, SYSDATETIME())
1131+
AND bs.backup_finish_date >= @StartTime
11321132
GROUP BY bs.database_name' + @crlf;
11331133

11341134
IF @Debug = 1
11351135
PRINT @StringToExecute;
11361136

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

11401140
RAISERROR('Rules analysis starting on temp tables', 0, 1) WITH NOWAIT;
11411141

0 commit comments

Comments
 (0)