-
Notifications
You must be signed in to change notification settings - Fork 0
/
Backup_Reports.sql
52 lines (50 loc) · 2.24 KB
/
Backup_Reports.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
SELECT [ServerName],
[DatabaseName],
[BackupSystem],
[FullBackup] = MAX([FullBackup]),
[DifferentialBackup] = MAX([DifferentialBackup]),
[LogBackup] = MAX([LogBackup]),
[DaysSinceLastFull] = DATEDIFF(DAY,MAX([FullBackup]),GETDATE())
FROM
(
SELECT [ServerName] = @@SERVERNAME,
[DatabaseName] = [A].[database_name],
[BackupSystem] = [A].[name],
[FullBackup] = MAX([A].[backup_finish_date]),
[DifferentialBackup] = NULL,
[LogBackup] = NULL
FROM [msdb].[dbo].[backupset] A INNER JOIN
[master].[dbo].[sysdatabases] B ON [A].[database_name] = [B].[name]
WHERE [A].[type] = 'D'
GROUP BY [A].[database_name],
[A].[name]
UNION ALL
SELECT [ServerName] = @@SERVERNAME,
[DatabaseName] = [A].[database_name],
[BackupSystem] = [A].[name],
[FullBackup] = NULL,
[DifferentialBackup] = MAX([A].[backup_finish_date]),
[LogBackup] = NULL
FROM [msdb].[dbo].[backupset] A INNER JOIN
[master].[dbo].[sysdatabases] B ON [A].[database_name] = [B].[name]
WHERE [A].[type] = 'I'
GROUP BY [A].[database_name],
[A].[name]
UNION ALL
SELECT [ServerName] = @@SERVERNAME,
[DatabaseName] = [A].[database_name],
[BackupSystem] = [A].[name],
[FullBackup] = NULL,
[DifferentialBackup] = NULL,
[LogBackup] = MAX([A].[backup_finish_date])
FROM [msdb].[dbo].[backupset] A INNER JOIN
[master].[dbo].[sysdatabases] B ON [A].[database_name] = [B].[name]
WHERE [A].[type] = 'L'
GROUP BY [A].[database_name],
[A].[name] ) B
WHERE BackupSystem IN ('NetAppBackup','CommVault Galaxy Backup','SQL Native')
GROUP BY [ServerName],
[DatabaseName],
[BackupSystem]
ORDER BY [DatabaseName],
[BackupSystem]