Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

last backup date query Expand / Collapse
Author
Message
Posted Tuesday, June 9, 2009 6:31 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, July 12, 2010 8:36 AM
Points: 26, Visits: 98
Does anyone know how SQL Server Management Studio knows when the last backup took place?

The specific query I am looking for is the the one that would populate the properties page if you right click on a database and select properties.

preferably this query will have nothing to do with sysjob tables, as I am trying to avoid working with these...
Post #731376
Posted Tuesday, June 9, 2009 6:36 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, July 12, 2010 8:36 AM
Points: 26, Visits: 98
i found the answer... and thought i'd share it for those of you who r interested:


select database_name,max(backup_finish_date) as backup_finish_date from msdb..backupset
where database_name='Libra'
group by database_name


There is also a useful article at:
http://code.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=LastBackUpDate

Post #731384
Posted Tuesday, June 9, 2009 8:14 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 3:46 PM
Points: 23,396, Visits: 32,227
Just a little thing, but may I suggest you write the query more like this:

select
database_name,
max(backup_finish_date) as backup_finish_date
from
msdb.dbo.backupset -- really should specify owner (SQL 2000)/schema (SQL 2005/2008)
where
database_name = 'Libra'
group by
database_name



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #731472
Posted Wednesday, October 6, 2010 7:42 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 17, 2013 6:42 AM
Points: 3, Visits: 27
Hi! The query is great, but I miss something that I want to use in my environment. I would also like to see the size and the set_id of that last (log) backup.

Tried this one:

select Database_name,
COALESCE(Convert(varchar(20), MAX(backup_finish_date), 113),'Backup Not Taken') as
LastBackUpTakenDate,
COALESCE(Convert(float, MAX(backup_size), 101),'NA') as BUsize,
COALESCE(Convert(float, MAX(backup_set_id), 101),'NA') as BUid
from msdb.dbo.backupset where type='L'
GROUP BY Database_name

But this gives me the last backup date, the maximum backup size, and the maximum backup_set_id. The first and the last are the right values, but I want to see the real size of that last backup. Anyone can help please?

Thanks, Roland.



If you pay peanuts you'll get monkey's...
Post #999298
Posted Wednesday, October 6, 2010 7:58 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:58 AM
Points: 5,369, Visits: 9,890
Roland

Try this.

John


  Post Attachments 
LatestBackups.txt (78 views, 789 bytes)
Post #999327
Posted Wednesday, October 6, 2010 8:05 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 17, 2013 6:42 AM
Points: 3, Visits: 27
Thanks John for this (complex) query. It gives me some of the correct output, but I have no idea how to filter out only the L backups...

If you pay peanuts you'll get monkey's...
Post #999340
Posted Wednesday, October 6, 2010 8:08 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:58 AM
Points: 5,369, Visits: 9,890
Mmmm.... surely by adding the line WHERE r.type = 'L' at the end?

John
Post #999346
Posted Wednesday, October 6, 2010 8:47 AM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, January 17, 2013 6:42 AM
Points: 3, Visits: 27
Thanks! That worked. Sorry for my newbie question, the query was a little too complex for me....

Regards,
Roland


If you pay peanuts you'll get monkey's...
Post #999422
Posted Wednesday, March 23, 2011 5:36 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, August 14, 2014 9:13 AM
Points: 98, Visits: 1,110
Hi All and thanks John this is a great script i will be using this from now on, but is there a way of outputting this in to a more printable format??

Thanks in advance!
Post #1082613
Posted Wednesday, March 23, 2011 5:38 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, August 14, 2014 9:13 AM
Points: 98, Visits: 1,110
extremenovice (3/23/2011)
Hi All and thanks John this is a great script i will be using this from now on, but is there a way of outputting this in to a more printable format??

Thanks in advance!


In conjunction with my previous post, how would i be able to run this for all my servers at once?

Once again thanks in advance!
Post #1082614
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse