![]() |
|
|
|
By: Tim Ford | Read Comments (9) | Related Tips: More > Backup |
Problem
There is a multitude of data to be mined from within the Microsoft SQL Server system views. This data is used to present information back to the end user of the SQL Server Management Studio (SSMS) and all third party management tools that are available for SQL Server Professionals. Be it database backup information, file statistics, indexing information, or one of the thousands of other metrics that the instance maintains, this data is readily available for direct querying and assimilation into your "home-grown" monitoring solutions as well. This tip focuses on that first metric: database backup information. Where it resides, how it is structured, and what data is available to be mined.
Solution
The msdb system database is the primary repository for storage of SQL Agent, backup, Service Broker, Database Mail, Log Shipping, restore, and maintenance plan metadata. We will be focusing on the handful of system views associated with database backups for this tip:
Based upon these tables, we can create a variety of queries to collect a detailed insight into the status of backups for the databases in any given SQL Server instance.
Database Backups for all databases For Previous Week
--------------------------------------------------------------------------------- |
Note: for readability the output was split into two screenshots.


Most Recent Database Backup for Each Database
------------------------------------------------------------------------------------------- |

Most Recent Database Backup for Each Database - Detailed
You can join the two result sets together by using the following query in order to return more detailed information about the last database backup for each database. The LEFT JOIN allows you to match up grouped data with the detailed data from the previous query without having to include the fields you do not wish to group on in the query itself.
------------------------------------------------------------------------------------------- |
Note: for readability the output was split into two screenshots.


Databases Missing a Data (aka Full) Back-Up Within Past 24 Hours
At this point we've seen how to look at the history for databases that have been backed up. While this information is important, there is an aspect to backup metadata that is slightly more important - which of the databases you administer have not been getting backed up. The following query provides you with that information (with some caveats.)
------------------------------------------------------------------------------------------- |
Now let me explain those caveats, and this query. The first part of the query returns all records where the last database (full) backup is older than 24 hours from the current system date. This data is then combined via the UNION statement to the second portion of the query. That second statement returns information on all databases that have no backup history. I've taken the liberty of singling tempdb out from the result set since you do not back up that system database. It is recreated each time the SQL Server services are restarted. That is caveat #1. Caveat #2 is the arbitrary value I've assigned to the aging value for databases without any backup history. I've set that value at 9999 hours because in my environment I want to place a higher emphasis on those databases that have never been backed up.
Using this final query I produce a report via SQL Server Reporting Services that is distributed to the DBA Team on a daily basis that highlights any missed backups. That, however, is for another tip.
Next Steps
| Friday, October 10, 2008 - 1:29:26 AM - tosc | Read The Tip |
|
Hi, or another way:
|
|
| Friday, October 24, 2008 - 6:58:31 AM - crcobb | Read The Tip |
|
Great scripts they have saved me a bunch of time getting a handle on the 25 SQL servers that I have inherited. I have been using your Back-up in the Past 24 hours and I found it was displaying Databases that have been deleted but there were still history enteries. I added an inner join so I only get results on existing databases. Chris -------------------------------------------------------------------------------------------
|
|
| Monday, May 21, 2012 - 9:17:02 AM - Dinesh Vishe | Read The Tip |
|
great .........I want to check using differnce backup type ???? |
|
| Tuesday, September 18, 2012 - 9:33:00 PM - Grazil | Read The Tip |
|
KUDOS! This really helped me! Thanks! |
|
| Wednesday, November 21, 2012 - 3:04:31 AM - Filip | Read The Tip |
|
This article is an example how it should be: simple, clear, to the point and very nicely presented ! This is thé added value of the www !
;-
Filip |
|
| Tuesday, February 12, 2013 - 4:59:25 AM - Diego | Read The Tip |
|
GREAT SCRIPTS everybody! Many thanks!!!! |
|
| Thursday, March 07, 2013 - 10:26:42 PM - unruledboy | Read The Tip |
|
Is the last db backup date same as "dbi_dbccLastKnownGood" from "DBCC DBINFO WITH TABLERESULTS"? |
|
| Saturday, March 16, 2013 - 2:48:53 AM - Shreenidhi R | Read The Tip |
|
Hi I have a question. I have done a restore on a pirticular database. The restore copy (.BAK) file was in two locations. But now I have deleted that two locations. All I want to know is that; Can I know the attributes of that .bak file which was restored on 17th feb which is in the DB. Because, all I know is that the .bak properties had "Modified date" which is the 17th of feb. So I m confused if I backed the wrong one or right one as I have deleted the backup location. Thanks! |
|
| Monday, April 22, 2013 - 1:04:01 PM - Rama | Read The Tip |
|
HI Tim Wonderful scripts. I have one question as Im a newbee in Sql Server. I have multiple instances across multiple database servers. i.e. N:N databases and instances For Ex: I have 30 different instances on 30 different servers as they all are different clients. I currently get 30 backup reports from all these servers by using your above queies on each server. My Question is --> Do you have any query which can get a consolidated report from all these 30 servers. i.e. instead of me getting 30 different emails I just want 1 email with all instance backup reports in that. Im trying to run this query from our Idear monitroing box - since this is the only box which can communicate to all the 30 diff servers so I thought this is the right place to run the big query.
Thx! Rama |
|
|
privacy | disclaimer | copyright | advertise | about authors | contribute | feedback | giveaways | user groups Some names and products listed are the registered trademarks of their respective owners. Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com |