T-SQL Tuesday: Connect item – Last Log Backup Time

T-SQL Tuesday is a blog party started by Adam Machanic (b/t) over five years ago. The first Tuesday of each month a blogger hosts the party and suggests a topic. Then anyone who is interested blogs on that topic on the second Tuesday. It can be a lot of fun and quite a challenge to blog on a topic you didn’t pick.

This month’s topic is presented by Brent Ozar (b/t), who has challenged us to find our favorite Bug report or feature request on MS Connect and write about it.

I don’t have a lot of experience with Connect, other than landing there from Google a few times while researching stuff.   I’m pretty sure I’ve never filed a report or request.  So, I just went looking through the latest requests and found one concerning “Check the time for the latest log backup” from none other than Ola Hallengren (w).

Ola’s feature request is:

I would like to ask for a way to check when the last log backup was performed.

His reasoning for the request:

This enables you to have a backup strategy with more frequent transaction log backups when there is a lot of activity in the database.

And his proposed solution:

Add a new column to sys.dm_db_log_space_usage or sys.database_recovery_status called LastLogBackupTime.

I LOVE this idea…back up the T-log more frequently during busy times, less often during off hours.  At my current client, there is almost nothing happening outside of a 12 hour workday window, so this would be perfect here.

Now, I am possibly misunderstanding Ola’s request or the intent…and that’s ok.  This query from the msdb..backupset table already contains this info via a relatively short amount of code:

Use MSDB
go

Select
    [Database_Name] as [Database Name],
    DB_id([database_name]) as [DB ID],
    Max(backup_Start_date) as [Last log backup]
From
    msdb..backupset bs
Where 1=1
    and db_id([database_name]) is not null
    and type = 'L'
Group by 
    [database_name]
Order By 
    Max(backup_start_date)

This returns a result set of:

So…the info requested can already be gathered.  There may very well be other ways to do this, or querying this table may be deprecated.  It seems that Ola is looking for a cleaner solution by adding to an existing System View in MSDB in order to more easily tie it to log size.

I do know and respect Ola’s maintenance scripts, so I have posted a comment on the Connect item asking for some clarification. And, I have voted it up.  I encourage YOU to do the same….as this simple request is probably going to wind up in his scripts 🙂

Thanks for reading!

Kevin3NF

Leave a Comment

Sign up for our Newsletter

%d bloggers like this: