Getting Started with ASP.NET MVC - Part 5: How to do programming with razor syntax
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.


Upload Image Close it
Select File

Towards the innovative SQL ideas
Browse by Tags · View All
ms sql server 97
ms sql 93
sql server 89
sql 88
database 75
#SQL Server 75
tsql 65
#sql 62
t-sql 59
sql server general 56

Archive · View All
April 2011 14
July 2011 12
May 2011 12
August 2011 11
June 2011 10
September 2011 8
December 2011 6
November 2011 6
February 2012 5
April 2012 4

SQL Server - Database Backup Statistics and History

Dec 16 2011 7:56AM by Paresh Prajapati   

Every DBA has a daily activity review or monitor database backups as these database backups used for the restoration at other place and using for the database restore which used for reporting purpose or used in log shipping purpose. Because database backups are most important factor and first option in case of disaster recovery even whatever types of them because in this case transaction logs can reduce the data loses.

You can read my earlier posts for Database Backup CompressionDatabase Backup files Verification Automated All Databases Backups Script and Split Database Full Backup to Multiple files.

I would like to share the script which help us to show the database backups status, history of their when they are done based on schedule, at where are taking and when, backup types , backups physical device and size of the database backups and time to perform backup and all other related backup statistics. Here is the script to collect the database backup statistics and status information.

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





















The transact-SQL for backupmediafamily and backupset are accordingly are http://msdn.microsoft.com/en-us/library/ms190284.aspx and http://msdn.microsoft.com/en-us/library/ms186299.aspx 

Hope you liked this post.

Tags: sql, sql server 2008, sql server 2005, tsql, ms sql, ms sql server, t-sql, #SQL Server, #sql, sql server 2011, database, sql server general, SQL Scripts, backup, statistics,


Paresh Prajapati
7 · 24% · 5483
4
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • You may want to consider putting an ELSE in every CASE statement. If this script is used with a compatability_level of something other than 80, 90, 100, 110, it will return a NULL. Same if Microsoft introduces a new backup_type.

    A number of calculated columns would also be useful:

    [Backup Duration(seconds)] = DATEDIFF(second, [backup_start_time], [backup_end_time])
    [Thruput (bytes per second)] = COALESCE([compressed_backup_size], [backup_size]) / DATEDIFF(second, [backup_start_time], [backup_end_time])
    [Compression Ratio] = CASE WHEN ISNULL([compressed_backup_size], 0) > 0 THEN [compressed_backup_size] / [backup_size] END
    

    You may also want to include data from msdb.dbo.backupfile so you can capture statistics about the size of the mdf, ndf and ldf files being backed up. This can be used to calculate the ratio between the size of the file being backed up and the size of the backup file.

    You have to remember that data will age out of msdb.dbo.backupset if you have scheduled sp_delete_backuphistory in order to keep the size of the msdb database manageable. It may be worth it to store the data derived from this query into a separate table. This can be very useful for tracking the performance of the backup subsystem. It can also be useful for storage forcecasting as you'll have file space statistics for both the database file size and the backup file size.

    commented on Jan 7 2012 12:26PM  .  Report Abuse This post is not formatted correctly
    Marc Jellinek
    119 · 2% · 357

Your Comment


Sign Up or Login to post a comment.

" SQL Server - Database Backup Statistics and History" rated 5 out of 5 by 4 readers
SQL Server - Database Backup Statistics and History , 5.0 out of 5 based on 4 ratings
    Copyright © Beyondrelational.com Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising