Last active
November 8, 2019 11:00
-
-
Save WimObiwan/36602574977bf3379eacc1b7bbf54b5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH BackupsPerDatabase AS | |
( | |
SELECT | |
--CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, | |
db.database_id, | |
bs.type, | |
MAX(bs.backup_finish_date) AS last_db_backup_date | |
FROM sys.databases db | |
LEFT OUTER JOIN msdb.dbo.backupset bs ON db.name = bs.database_name | |
INNER JOIN msdb.dbo.backupmediafamily bmf ON bmf.media_set_id = bs.media_set_id | |
GROUP BY db.database_id, bs.type | |
), BackupsPerDatabase2 AS | |
( | |
SELECT * FROM BackupsPerDatabase | |
PIVOT | |
( | |
MAX(last_db_backup_date) | |
FOR [type] in ([D], [I], [L]) --, [F], [G], [P], [Q]) | |
) as pvt | |
) | |
SELECT @@SERVERNAME server, db.name dbname, db.create_date, db.recovery_model_desc,b.D, b.I, b.L | |
FROM BackupsPerDatabase2 b | |
INNER JOIN sys.databases db on db.database_id = b.database_id | |
ORDER BY 1, 2 | |
-- https://docs.microsoft.com/en-us/sql/relational-databases/system-tables/backupset-transact-sql?view=sql-server-2017 | |
--type | |
-- Backup type. Can be: | |
-- D = Database | |
-- I = Differential database | |
-- L = Log | |
-- F = File or filegroup | |
-- G = Differential file | |
-- P = Partial | |
-- Q = Differential partial | |
-- Can be NULL. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, | |
db.name, | |
bs.type, | |
MAX(bs.backup_finish_date) AS last_db_backup_date | |
FROM sys.databases db | |
LEFT OUTER JOIN msdb.dbo.backupset bs ON db.name = bs.database_name | |
INNER JOIN msdb.dbo.backupmediafamily bmf ON bmf.media_set_id = bs.media_set_id | |
GROUP BY db.name, bs.type | |
ORDER BY db.name, bs.type | |
-- https://docs.microsoft.com/en-us/sql/relational-databases/system-tables/backupset-transact-sql?view=sql-server-2017 | |
--type | |
-- Backup type. Can be: | |
-- D = Database | |
-- I = Differential database | |
-- L = Log | |
-- F = File or filegroup | |
-- G = Differential file | |
-- P = Partial | |
-- Q = Differential partial | |
-- Can be NULL. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment