Agent Jobs

Get How Old SQL Database Backups Are

Here’s some quick SQL Logic that will show you the age of your backups.

use master;
set nocount on

select
'database' = upper(bs.database_name)
,	'backup date' = datename(dw, bs.backup_finish_date) + ' ' + convert(char, bs.backup_finish_date, 9) ,	'type' =
case bs.type
when 'L' then 'TLOG'
when 'D' then 'FULL'
end
,	'num days old' = left((datediff(s, bs.backup_finish_date, getdate())/86400.0),6) ,	'location' = bmf.physical_device_name
from
msdb..backupset bs join msdb..backupmediafamily bmf on bs.media_set_id = bmf.media_set_id
--where
--	bs.database_name = 'mydatabase'
--	and bs.type = 'D'
order by
bs.backup_finish_date desc
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s