Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Towards the innovative SQL ideas
Browse by Tags · View All
ms sql server 119
ms sql 118
sql server 116
sql 115
database 102
tsql 81
#SQL Server 78
t-sql 75
#sql 71
sql server general 67

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
June 2013 5
April 2013 5

SQL Server - Database Backup Statistics and History

Dec 16 2011 12:00AM 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 


















(Click on image to enlarge) 
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
6 · 22% · 7044
5
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

2  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
    Marc Jellinek
    97 · 2% · 545
  • Thanks for sharing this script.

    commented on Jan 1 2013 1:30AM
    Krishnrajsinh Rana
    136 · 1% · 360

Your Comment


Sign Up or Login to post a comment.

" SQL Server - Database Backup Statistics and History" rated 5 out of 5 by 5 readers
SQL Server - Database Backup Statistics and History , 5.0 out of 5 based on 5 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]