SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


last backup date query


last backup date query

Author
Message
harriet.louis
harriet.louis
SSC Veteran
SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)

Group: General Forum Members
Points: 219 Visits: 109
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...Hehe
harriet.louis
harriet.louis
SSC Veteran
SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)SSC Veteran (219 reputation)

Group: General Forum Members
Points: 219 Visits: 109
i found the answer...:-P 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
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)SSC Guru (95K reputation)

Group: General Forum Members
Points: 95199 Visits: 38967
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

Cool
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)
Roland [GISS]
Roland [GISS]
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 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...
John Mitchell-245523
John Mitchell-245523
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34789 Visits: 16661
Roland

Try this.

John
Attachments
LatestBackups.txt (151 views, 789 bytes)
Roland [GISS]
Roland [GISS]
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 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...
John Mitchell-245523
John Mitchell-245523
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34789 Visits: 16661
Mmmm.... surely by adding the line WHERE r.type = 'L' at the end?

John
Roland [GISS]
Roland [GISS]
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 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...
extremenovice
extremenovice
SSC-Addicted
SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)

Group: General Forum Members
Points: 432 Visits: 1140
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!
extremenovice
extremenovice
SSC-Addicted
SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)SSC-Addicted (432 reputation)

Group: General Forum Members
Points: 432 Visits: 1140
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!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search