{"id":1123,"date":"2009-10-26T22:50:34","date_gmt":"2009-10-26T20:50:34","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=1123"},"modified":"2010-09-01T12:17:54","modified_gmt":"2010-09-01T10:17:54","slug":"check-last-successful-full-backup-of-exchange-2007","status":"publish","type":"post","link":"https:\/\/contoso.se\/blog\/?p=1123","title":{"rendered":"Check last successful full backup of Exchange 2007"},"content":{"rendered":"<p>I found a nice script from <a href=\"http:\/\/www.flobee.net\/\">Scott<\/a>\u00c2\u00a0that reports on last successful full backup of Exchange 2007. If you want to do that from Operations Manager 2007 you could modify the power shell script a bit..\u00c2\u00a0The power shell\u00c2\u00a0script below checks when last full backup was made,\u00c2\u00a0it checks for the presence of storage groups and databases within them. You could store the script at your Exchange mailbox servers, in for example C:\\temp\\LastBackupReport.ps1, and then call it from a monitor with a vbscript.<\/p>\n<blockquote><p>$iNomHours = &#8220;1&#8221; #Enter number of hours since last backup that requires attention<\/p>\n<p>if (-not (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin -ErrorAction SilentlyContinue))<br \/>\n\u00c2\u00a0{Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin}<\/p>\n<p>function BackupStatus<br \/>\n\u00c2\u00a0{<br \/>\n\u00c2\u00a0param($db)<br \/>\n\u00c2\u00a0$sBackupRunning = &#8220;&#8221;<br \/>\n\u00c2\u00a0$sCMStatus = $sCheckMark<br \/>\n\u00c2\u00a0#Note if backup is currently running<br \/>\n\u00c2\u00a0If ($db.BackupInProgress -eq $true)<br \/>\n\u00c2\u00a0\u00c2\u00a0{$sBackupRunning = &#8220;(Backup In Progress)&#8221;}<br \/>\n\u00c2\u00a0#Determine if backup has ever completed<br \/>\n\u00c2\u00a0If ($db.LastFullBackup -ne $null)<br \/>\n\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0$sBackupDay = $db.LastFullBackup.get_DayofWeek()<br \/>\n\u00c2\u00a0\u00c2\u00a0$sBackupDateTime = $db.LastFullBackup.ToString(&#8220;g&#8221;)<br \/>\n\u00c2\u00a0\u00c2\u00a0#Flag if last completed backup started over 1 hours ago<br \/>\n\u00c2\u00a0\u00c2\u00a0If (($date &#8211; $db.LastFullBackup).TotalHours -gt $iNomHours)<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0$sLastBackup = &#8220;Last Backup Started: &#8221; + $sBackupDay + &#8220;, &#8221; + $sBackupDateTime<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0$sCMStatus = &#8220;&#8221;<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0$script:bAlert = $true<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0\u00c2\u00a0Else<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0$sLastBackup = &#8220;Last Backup Started: &#8221; + $sBackupDay + &#8220;, &#8221; + $sBackupDateTime<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0Else<br \/>\n\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0$sLastBackup = &#8220;No full backup has completed yet&#8221;<br \/>\n\u00c2\u00a0\u00c2\u00a0$sCMStatus = &#8220;&#8221;<br \/>\n\u00c2\u00a0\u00c2\u00a0$script:bAlert = $true<br \/>\n\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0$script:sOutput += &#8220;&#8221; + $sSpace + $sSpace + $db.Name + &#8221; &#8221; + `<br \/>\n\u00c2\u00a0\u00c2\u00a0$sLastBackup + &#8220;&#8221; + $sCMStatus + &#8221; &#8221; + $sBackupRunning + &#8220;&#8221;<br \/>\n\u00c2\u00a0}<\/p>\n<p>$date = Get-Date<br \/>\n$sSpace = &#8221; &#8221;<br \/>\n$sOutput = &#8220;indicates that no backup started within the configured timeframe, which is &#8221; + $iNomHours + &#8221; hours.&#8221;<\/p>\n<p>#Retrieve Exchange servers with mailbox role<br \/>\n$ExServer = Get-ExchangeServer | where {$_.IsMailboxServer -eq $True} | Sort-Object Name<br \/>\nForeach ($server in $ExServer)<br \/>\n\u00c2\u00a0{<br \/>\n\u00c2\u00a0$sOutput += $server<br \/>\n\u00c2\u00a0#Retrieve storage groups for a given server<br \/>\n\u00c2\u00a0$StorageGroup = $server | Get-StorageGroup | Sort-Object Name<br \/>\n\u00c2\u00a0#Check for absence of any storage groups<br \/>\n\u00c2\u00a0If (($StorageGroup | Measure-Object Name).Count -eq $null)<br \/>\n\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0$sOutput += $sSpace + &#8220;No storage groups present.&#8221;<br \/>\n\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0Else<br \/>\n\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0Foreach ($sg in $StorageGroup)<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0$sOutput += $sSpace + $sg.Name<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0#Retrieve mailbox databases for a given storage group<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0$MailboxDatabase = $sg | Get-MailboxDatabase -Status | Sort-Object Name<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0$PFDatabase = $sg | Get-PublicFolderDatabase -Status<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0#Check for absence of any databases in storage group<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0$bMdbExist = ($MailboxDatabase | Measure-Object Name).Count -ne $null<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0$bPFExist = ($PFDatabase | Measure-Object Name).Count -ne $null<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0If ((!$bMdbExist) -and (!$bPFExist))<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0$sOutput += $sSpace + $sSpace + &#8220;No databases in storage group.&#8221;<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0Else<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0if ($bMdbExist)<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0Foreach ($mdb in $MailboxDatabase)<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0BackupStatus $mdb<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0if ($bPFExist)<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0{<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0BackupStatus $PFDatabase<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0\u00c2\u00a0}<br \/>\n\u00c2\u00a0}<br \/>\n$sOutput += &#8220;&#8221;<br \/>\nIf ($bAlert -eq $true)<br \/>\n\u00c2\u00a0{<br \/>\n\u00c2\u00a0Write-host &#8220;Attention Required&#8221;<br \/>\n\u00c2\u00a0Write-Host $bAlert<br \/>\n\u00c2\u00a0Write-host $sOutput<br \/>\n\u00c2\u00a0}<br \/>\nElse<br \/>\n\u00c2\u00a0{<br \/>\n\u00c2\u00a0Write-host &#8220;All ok&#8221;<br \/>\n\u00c2\u00a0}<br \/>\n\u00c2\u00a0<br \/>\n\u00c2\u00a0<\/p><\/blockquote>\n<p>The VB script below is used in a timed script two state monitor<\/p>\n<blockquote><p>pscommand = &#8220;C:\\temp\\LastBackupReport.ps1&#8221;<br \/>\ncmd = &#8220;powershell.exe &#8221; &amp; pscommand<br \/>\nSet shell = createObject(&#8220;Wscript.Shell&#8221;)<br \/>\nSet executor = shell.exec(cmd)<br \/>\nexecutor.StdIn.Close<br \/>\nvarPSResult = executor.StdOut.ReadAll<br \/>\nvarString = InStr(varPSResult, &#8220;True&#8221;)<br \/>\nDim oAPI, oBag<br \/>\nSet oAPI = CreateObject(&#8220;MOM.ScriptAPI&#8221;)<br \/>\nSet oBag = oAPI.CreatePropertyBag()<br \/>\nCall oBag.AddValue(&#8220;varPSResult&#8221;,varPSResult)<br \/>\nIf varString &gt; 1 Then<br \/>\nCall oBag.AddValue(&#8220;Backup&#8221;,&#8221;Error&#8221;)<br \/>\nCall oAPI.Return(oBag)<br \/>\nElse<br \/>\nCall oBag.AddValue(&#8220;Backup&#8221;,&#8221;Ok&#8221;)<br \/>\nCall oAPI.Return(oBag)<br \/>\nEnd If<\/p><\/blockquote>\n<p>Settings for the monitor (Timed Script Two State Monitor)<\/p>\n<ul>\n<li>General. Monitor target: Exchange 2007 Standalone Mailbox Role<\/li>\n<li>Schedule. Run every X hours<\/li>\n<li>Script. File Name: ExchangeBackup.vbs<\/li>\n<li>Script. Timeout:\u00c2\u00a02 Minutes<\/li>\n<li>Script. Paste the script in<\/li>\n<li>Unhealthy Expression: Property[@Name=&#8217;Backup&#8217;] Does not equal Ok<\/li>\n<li>Healthy Expression: Property[@Name=&#8217;Backup&#8217;]\u00c2\u00a0Equal Ok<\/li>\n<li>Alerting. check Generate alerts for this monitor<\/li>\n<li>Alerting. Alert description: $Data\/Context\/Property[@Name&#8217;varPSResult&#8217;]$ No backup for the last X hours<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I found a nice script from Scott\u00c2\u00a0that reports on last successful full backup of Exchange 2007. If you want to do that from Operations Manager 2007 you could modify the power shell script a bit..\u00c2\u00a0The power shell\u00c2\u00a0script below checks when last full backup was made,\u00c2\u00a0it checks for the presence of storage groups and databases within &hellip; <a href=\"https:\/\/contoso.se\/blog\/?p=1123\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[13,19],"tags":[],"_links":{"self":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1123"}],"collection":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1123"}],"version-history":[{"count":7,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1123\/revisions"}],"predecessor-version":[{"id":1749,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1123\/revisions\/1749"}],"wp:attachment":[{"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}