How to find the latest backup of the database
All the database backup information is written to MSDB database. A quick workaround in this database will give lot of information about the database backup happening in the current server.
Below query will fetch all necessary details from MSDB database.
Inputs like
changing the date at 3rd line from last
changing the database at 2nd line from last
If the filter is provided on the above mentioned then the query will return the precise information needed or else the below query will show all the backups currently resding in MSDB database.
SELECT sysdb.name, bkup.description,bkup.backup_start_date, bkup.backup_finish_date,bkmf.physical_device_name,
,user_name, sysdb.crdate,datediff(minute, bkup.backup_start_date, bkup.backup_finish_date) as 'Mins' ,cast(cast(datediff(minute, bkup.backup_start_date, bkup.backup_finish_date) as decimal (8,3))/60 as decimal (8,1)) as 'Hours', first_lsn, last_lsn, checkpoint_lsn FROM master.dbo.sysdatabases sysdb LEFT OUTER JOIN msdb.dbo.backupset bkup ON bkup.database_name = sysdb.name join msdb.dbo.backupmediafamily bkmf ON bkup.media_set_id=bkmf.media_set_id where backup_finish_date > DATEADD(DAY, -30, (getdate())) /*Last 30 days-- AND sysdb.name = 'Mydb' */ORDER BY sysdb.name, bkup.backup_finish_date desc
Hope the above query is usefull for DBA day to day task
Revert to me if found any issues or need any help
Thanks