Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions sp_BlitzBackups.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,42 @@ IF @ProductVersionMajor >= 12
INSERT #Warnings ( CheckId, Priority, DatabaseName, Finding, Warning )
EXEC sys.sp_executesql @StringToExecute;

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

SET @StringToExecute += N'SELECT
14 AS CheckId,
100 AS [Priority],
bs.database_name AS [Database Name],
''Backup to NUL device'' AS [Finding],
''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 ''+
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's remove the 30 day reference and just say "backups to the NUL device, the latest one being on" since we're using the @HoursBack parameter.

CONVERT(NVARCHAR(25),MAX(bs.backup_finish_date),120)+''. These backups do not exist.'' AS [Warning]
FROM ' + QUOTENAME(@MSDBName) + '.dbo.backupset AS bs
INNER JOIN ' + QUOTENAME(@MSDBName) + '.dbo.backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
WHERE UPPER(bmf.physical_device_name)= N''NUL''
AND (bs.is_copy_only = 1 OR bs.recovery_model = N''SIMPLE'')
AND bs.backup_finish_date >= DATEADD(DAY, -30, SYSDATETIME())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of hard-coding 30 days back, let's use the @starttime variable, which is set via the @HoursBack input parameter on the stored proc.

GROUP BY bs.database_name' + @crlf;
SET @StringToExecute += N'UNION ALL' + @crlf + N'SELECT
14 AS CheckId,
100 AS [Priority],
bs.database_name AS [Database Name],
''Backup to NUL device without COPY_ONLY'' AS [Finding],
''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 ''+
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's remove the 30 day reference and just say "backups to the NUL device, the latest one being on" since we're using the @HoursBack parameter.

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]
FROM ' + QUOTENAME(@MSDBName) + '.dbo.backupset AS bs
INNER JOIN ' + QUOTENAME(@MSDBName) + '.dbo.backupmediafamily bmf ON bs.media_set_id = bmf.media_set_id
WHERE UPPER(bmf.physical_device_name)= N''NUL''
AND bs.is_copy_only = 0 AND bs.recovery_model <> N''SIMPLE''
AND bs.backup_finish_date >= DATEADD(DAY, -30, SYSDATETIME())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of hard-coding 30 days back, let's use the @starttime variable, which is set via the @HoursBack input parameter on the stored proc.

GROUP BY bs.database_name' + @crlf;

IF @Debug = 1
PRINT @StringToExecute;

INSERT #Warnings ( CheckId, Priority, DatabaseName, Finding, Warning )
EXEC sys.sp_executesql @StringToExecute;

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

INSERT #Warnings ( CheckId, Priority, DatabaseName, Finding, Warning )
Expand Down