Home » Scripts » Check last successful full backup of Exchange 2007

Check last successful full backup of Exchange 2007

I found a nice script from Scott that 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.. The power shell script below checks when last full backup was made, it 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.

$iNomHours = “1” #Enter number of hours since last backup that requires attention

if (-not (Get-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin -ErrorAction SilentlyContinue))
 {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin}

function BackupStatus
 {
 param($db)
 $sBackupRunning = “”
 $sCMStatus = $sCheckMark
 #Note if backup is currently running
 If ($db.BackupInProgress -eq $true)
  {$sBackupRunning = “(Backup In Progress)”}
 #Determine if backup has ever completed
 If ($db.LastFullBackup -ne $null)
  {
  $sBackupDay = $db.LastFullBackup.get_DayofWeek()
  $sBackupDateTime = $db.LastFullBackup.ToString(“g”)
  #Flag if last completed backup started over 1 hours ago
  If (($date – $db.LastFullBackup).TotalHours -gt $iNomHours)
   {
   $sLastBackup = “Last Backup Started: ” + $sBackupDay + “, ” + $sBackupDateTime
   $sCMStatus = “”
   $script:bAlert = $true
   }
  Else
   {
   $sLastBackup = “Last Backup Started: ” + $sBackupDay + “, ” + $sBackupDateTime
   }
  }
 Else
  {
  $sLastBackup = “No full backup has completed yet”
  $sCMStatus = “”
  $script:bAlert = $true
  }
 $script:sOutput += “” + $sSpace + $sSpace + $db.Name + ” ” + `
  $sLastBackup + “” + $sCMStatus + ” ” + $sBackupRunning + “”
 }

$date = Get-Date
$sSpace = ” ”
$sOutput = “indicates that no backup started within the configured timeframe, which is ” + $iNomHours + ” hours.”

#Retrieve Exchange servers with mailbox role
$ExServer = Get-ExchangeServer | where {$_.IsMailboxServer -eq $True} | Sort-Object Name
Foreach ($server in $ExServer)
 {
 $sOutput += $server
 #Retrieve storage groups for a given server
 $StorageGroup = $server | Get-StorageGroup | Sort-Object Name
 #Check for absence of any storage groups
 If (($StorageGroup | Measure-Object Name).Count -eq $null)
  {
  $sOutput += $sSpace + “No storage groups present.”
  }
 Else
  {
  Foreach ($sg in $StorageGroup)
   {
   $sOutput += $sSpace + $sg.Name
   #Retrieve mailbox databases for a given storage group
   $MailboxDatabase = $sg | Get-MailboxDatabase -Status | Sort-Object Name
   $PFDatabase = $sg | Get-PublicFolderDatabase -Status
   #Check for absence of any databases in storage group
   $bMdbExist = ($MailboxDatabase | Measure-Object Name).Count -ne $null
   $bPFExist = ($PFDatabase | Measure-Object Name).Count -ne $null
   If ((!$bMdbExist) -and (!$bPFExist))
    {
    $sOutput += $sSpace + $sSpace + “No databases in storage group.”
    }
   Else
    {
    if ($bMdbExist)
     {
      Foreach ($mdb in $MailboxDatabase)
      {
      BackupStatus $mdb
      }
     }
    if ($bPFExist)
     {
     BackupStatus $PFDatabase
     }
    }
   }
  }
 }
$sOutput += “”
If ($bAlert -eq $true)
 {
 Write-host “Attention Required”
 Write-Host $bAlert
 Write-host $sOutput
 }
Else
 {
 Write-host “All ok”
 }
 
 

The VB script below is used in a timed script two state monitor

pscommand = “C:\temp\LastBackupReport.ps1”
cmd = “powershell.exe ” & pscommand
Set shell = createObject(“Wscript.Shell”)
Set executor = shell.exec(cmd)
executor.StdIn.Close
varPSResult = executor.StdOut.ReadAll
varString = InStr(varPSResult, “True”)
Dim oAPI, oBag
Set oAPI = CreateObject(“MOM.ScriptAPI”)
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue(“varPSResult”,varPSResult)
If varString > 1 Then
Call oBag.AddValue(“Backup”,”Error”)
Call oAPI.Return(oBag)
Else
Call oBag.AddValue(“Backup”,”Ok”)
Call oAPI.Return(oBag)
End If

Settings for the monitor (Timed Script Two State Monitor)

  • General. Monitor target: Exchange 2007 Standalone Mailbox Role
  • Schedule. Run every X hours
  • Script. File Name: ExchangeBackup.vbs
  • Script. Timeout: 2 Minutes
  • Script. Paste the script in
  • Unhealthy Expression: Property[@Name=’Backup’] Does not equal Ok
  • Healthy Expression: Property[@Name=’Backup’] Equal Ok
  • Alerting. check Generate alerts for this monitor
  • Alerting. Alert description: $Data/Context/Property[@Name’varPSResult’]$ No backup for the last X hours

4 Comments

  1. Hello,
    Unfornuately, the free edition seems to be retired !!!!
    Where can we download this edition ?

    Thanks in advance for your help !!!

    BR

  2. Hi Guys,

    Thanks for sharing your insightful thoughts and suggestions – very helpful, and appreciated indeed.

    On a related note, recently we needed a quick and efficient way to find out which accounts were OWA enabled (for an internal security audit) so we asked our on-site MS consultant and he recommended using the Gold Finger from Paramount Defenses Inc.

    Gold Finger pleasantly surprised us because not only was it endorsed by Microsoft but also 100% FREE and loaded with almost 250 useful Active Directory security, Exchange and ACL management reports. BTW, you can download it for free from http://goldfinger.paramountdefenses.com

    In particular, it has over 60 inbuilt Exchange reports, including OWA and MAPI enabled accounts. For a complete list of reports, checkout http://www.paramountdefenses.com/goldfinger_security_reports_exchange_management.php

    Thought I’d share this with you incase it could help you too, especially if you need a free way to generate Exchange and AD security reports.

    Thanks again, and looking forward to your next post.

    Best wishes,
    Jonathan

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.