Skip to content

Commit 686c033

Browse files
committed
Fix author rights and add some useful checks and parameters
1 parent 80df14a commit 686c033

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

Scripts/Which_databases_were_backed_up_and_when.sql

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/*
2-
Author: Buck Woody
2+
Author: thelonedba
33
Original link: https://thelonedba.wordpress.com/2016/07/18/which-databases-were-backed-up-in-which-backup-task/
44
*/
55

6-
76
DECLARE @SQL VARCHAR(MAX);
87
DECLARE @RunStartedList VARCHAR(MAX);
98
DECLARE @NumDays INT;
10-
SELECT @NumDays = 10; -- not doing this as a single line declare-define, as we might be running on older versions.
9+
SET @NumDays = 10; -- not doing this as a single line declare-define, as we might be running on older versions.
10+
DECLARE @THROW50000 VARCHAR(200);
11+
SET @THROW50000 = 'Still no backups on this server on last ' + CAST(@NumDays AS VARCHAR(50)) + ' days - please fix it!';
12+
DECLARE @debug BIT = 0;
1113

1214
IF @NumDays > 0
1315
BEGIN
@@ -25,7 +27,9 @@ SELECT @RunStartedList = STUFF(( SELECT ', ' + QUOTENAME(CONVERT(VARCHAR(20)
2527
FOR
2628
XML PATH('')
2729
), 1, 2, '');
28-
30+
31+
IF @RunStartedList IS NULL THROW 50000, @THROW50000, 1;
32+
2933
SELECT @SQL = '
3034
WITH JobRuns
3135
AS ( SELECT jh.instance_id ,
@@ -67,6 +71,9 @@ FROM BackupPivot bp
6771
ORDER BY sd.name ,
6872
bp.DBName
6973
;
70-
';
71-
--SELECT @SQL;
72-
EXEC (@SQL);
74+
';
75+
76+
IF @debug = 1 PRINT(@SQL);
77+
ELSE
78+
EXEC(@SQL);
79+

0 commit comments

Comments
 (0)