{"id":13,"date":"2021-07-21T11:22:04","date_gmt":"2021-07-21T09:22:04","guid":{"rendered":"http:\/\/130.61.57.200\/?p=13"},"modified":"2024-10-24T11:08:38","modified_gmt":"2024-10-24T09:08:38","slug":"check-backups","status":"publish","type":"post","link":"http:\/\/130.61.57.200\/index.php\/2021\/07\/21\/check-backups\/","title":{"rendered":"Check Backups"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Following statement can be used to see the last backups of all databases.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You get information of last backup&#8217;s start time, end time, duration in minutes, hours since last backup both for full and log backups.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT db.name,db.recovery_model_desc,d.[Database Backup Start],d.[Database Backup End], datediff(mi,d.[Database Backup Start],d.[Database Backup End]) as [Minutes Duration],<br>cast (datediff(hh,d.[Database Backup End],SYSDATETIME()) as nvarchar)+':'+ right ('000'+cast (datediff(mi,d.[Database Backup End],SYSDATETIME()) % 60 as nvarchar),2) [Since Last Backup],i.[Database Backup Start],i.[Database Backup End], datediff(mi,i.[Database Backup Start],i.[Database Backup End]) as [Minutes Duration],<br>cast (datediff(hh,i.[Database Backup End],SYSDATETIME()) as nvarchar)+':'+ right ('000'+cast (datediff(mi,i.[Database Backup End],SYSDATETIME()) % 60 as nvarchar),2) [Since Last Backup],<br>l.[Log Backup Start],l.[Log Backup End] , datediff(ss,l.[Log Backup Start],l.[Log Backup End]) as seconds,<br>case when db.recovery_model_desc='SIMPLE' then 'SIMPLE RM' else cast (datediff(mi,L.[Log Backup End],SYSDATETIME()) as nvarchar) end [RPO]<br>from<br>(select name,recovery_model_desc from sys.databases where name&lt;>'tempdb') db left outer join<br>(<br>SELECT sdb.Name AS DatabaseName, max(backup_start_date) as [Database Backup Start],MAX(bus.backup_finish_date) as [Database Backup End]<br>FROM sys.sysdatabases sdb<br>LEFT OUTER JOIN msdb.dbo.backupset bus ON bus.database_name = sdb.name<br>where type='D'<br>and sdb.dbid&lt;>2<br>GROUP BY sdb.Name,type) d on d.DatabaseName=db.name<br>left outer join<br>(SELECT sdb.Name AS DatabaseName, max(backup_start_date) as [Database Backup Start],MAX(bus.backup_finish_date) as [Database Backup End]<br>FROM sys.sysdatabases sdb<br>LEFT OUTER JOIN msdb.dbo.backupset bus ON bus.database_name = sdb.name<br>where type='I'<br>and sdb.dbid&lt;>2<br>GROUP BY sdb.Name,type) I<br>on d.databaseNAme=i.DatabaseName<br>left outer join<br>(SELECT sdb.Name AS DatabaseName, max(backup_start_date) as [Log Backup Start],MAX(bus.backup_finish_date) as [Log Backup End]<br>FROM sys.sysdatabases sdb<br>LEFT OUTER JOIN msdb.dbo.backupset bus ON bus.database_name = sdb.name<br>where type='L'<br>and sdb.dbid&lt;>2<br>GROUP BY sdb.Name,type) L<br>on d.databaseNAme=l.DatabaseName<br>GO<br><br><br><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Following statement can be used to see the last backups of all databases. You get information of last backup&#8217;s start time, end time, duration in minutes, hours since last backup both for full and log backups. SELECT db.name,db.recovery_model_desc,d.[Database Backup Start],d.[Database Backup End], datediff(mi,d.[Database Backup Start],d.[Database Backup End]) as [Minutes Duration],cast (datediff(hh,d.[Database Backup End],SYSDATETIME()) as nvarchar)+&#8217;:&#8217;+ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[10],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-mssql","tag-backup"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[]}},"_links":{"self":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":3,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":232,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/posts\/13\/revisions\/232"}],"wp:attachment":[{"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/130.61.57.200\/index.php\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}