forked from Arvindpoongothai/SQLDBAInventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackup--Backup History
43 lines (42 loc) · 1.82 KB
/
Backup--Backup History
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
--Backup History
--Script to get the database backup history on SQL Server 2000/2005/2008
USE msdb
GO
SELECT bs.server_name AS Server,-- Server name
bs.database_name AS DatabseName,-- Database name
CASE bs.compatibility_level
WHEN 80 THEN 'SQL Server 2000'
WHEN 90 THEN 'SQL Server 2005 '
WHEN 100 THEN 'SQL Server 2008'
WHEN 110 THEN 'SQL Server 2011'
END AS CompatibilityLevel,
-- Return backup compatibility level
recovery_model AS Recoverymodel,-- Database recovery model
CASE bs.type
WHEN 'D' THEN 'Full'
WHEN 'I' THEN 'Differential'
WHEN 'L' THEN 'Log'
WHEN 'F' THEN 'File or filegroup'
WHEN 'G' THEN 'Differential file'
WHEN 'P' THEN 'P'
WHEN 'Q' THEN 'Differential partial'
END AS BackupType,-- Type of database baclup
bs.backup_start_date AS BackupstartDate,-- Backup start date
bs.backup_finish_date AS BackupFinishDate,-- Backup finish date
bmf.physical_device_name AS PhysicalDevice,-- baclup Physical localtion
CASE device_type
WHEN 2 THEN 'Disk - Temporary'
WHEN 102 THEN 'Disk - Permanent'
WHEN 5 THEN 'Tape - Temporary'
WHEN 105 THEN 'Tape - Temporary'
ELSE 'Other Device'
END AS DeviceType,-- Device type
bs.backup_size AS [BackupSize(In bytes)],
-- Normal backup size (In bytes)
compressed_backup_size AS [ConmpressedBackupSize(In bytes)]
-- Compressed backup size (In bytes)
FROM msdb.dbo.backupset bs
INNER JOIN msdb.dbo.backupmediafamily bmf
ON ( bs.media_set_id = bmf.media_set_id )
ORDER BY bs.backup_start_date DESC
GO