Friday, February 10, 2012

Backup and Restore History of a Particular DB

-- Backup History

SELECT s.backup_set_id,s.user_name,s.backup_start_date,s.backup_finish_date,
datediff(mi,s.backup_start_date,s.backup_finish_date)as mins,
datediff(s,s.backup_start_date,s.backup_finish_date)as sec,
s.type,s.backup_size,s.database_name,f.physical_device_name,s.server_name,
s.recovery_model
from msdb..backupset s,msdb..backupmediafamily f
where s.media_set_id=f.media_set_id --and s.database_name='{Database name}'
order by s.backup_finish_date DESC


-- Restore History

SELECT h.backup_set_id,h.destination_database_name,f.physical_device_name,
h.restore_date ,h.user_name,h.restore_type,h.replace,s.server_name
from msdb..restorehistory h,msdb..backupmediafamily f,msdb..backupset s
where h.backup_set_id=s.backup_set_id and s.media_set_id=f.media_set_id
--and h.destination_database_name ='{Database name}'
ORDER BY h.restore_date DESC

No comments: