-
Notifications
You must be signed in to change notification settings - Fork 1.1k
for #3959 - added check for backup to NUL device #3960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ''+ | ||
| 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()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ''+ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ) | ||
|
|
||
There was a problem hiding this comment.
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.