System Center Data Protection Manager

Check Last Backup, Version 1.3 available

There is a new release of my “Check Last Backup” SCDPM Script. I have done some modification on the Code and added some new Features.

Skip HyperV now reports the span Days, so you can see if there is a Problem.

The query for running Job now ignores Tape Jobs.

And we now create a Summary Report and you will be able to send this via mail.

Hope you like the new Script, here is the Code, at the End is the Link to TechNet Gallery Download. Please rate and comment for new Features.

The Script

########################################################
# Name: CheckLastBackups.ps1                              
# Creator: Michael Seidl aka Techguy                    
# CreationDate: 27.06.2014                              
# LastModified: 19.01.2016                              
# Version: 1.3                                      
# Doc: http://www.techguy.at/tag/checklastbackups/
#
# Description: Get all Disk Datasources from your
# DPM Server and compare the last Recoverypoint with your
# configured SpanDays. So you can controll if your
# Datasources are up do date  
#   
# Variables
# SpanDays: How many Days in the past from Today your
# Datasources should have a valid Recoverypoint
# Checkonly: will only Log the Result, would not start
# a recoveryPoint creation
#
# Version 1.3 - NEW: Query for running Job skip TapeJobs
#               NEW: Skip HyperV still reports
#               NEW: Summary Report
#
# Version 1.2 - NEW: Skip HyperV
#
# Version 1.1 - NEW: Parameters added
#               NEW: Log can be sent via Email
#               NEW: Run a Checkonly mode
#               NEW: Check if there is already a Job for affected Datasource
#
#
# Version 1.0 - RTM
########################################################
#
# www.techguy.at                                        
# www.facebook.com/TechguyAT                            
# www.twitter.com/TechguyAT                             
# michael@techguy.at 
########################################################



#Parameter
Param(
   [Parameter(Mandatory=$false)][string]$DPMServerName,
   [Parameter(Mandatory=$false)][string]$Spandays,
   [Parameter(Mandatory=$false)][switch]$Checkonly,
   [Parameter(Mandatory=$false)][switch]$SkipHyperV,
   [Parameter(Mandatory=$false)][switch]$LogPublic,
   [Parameter(Mandatory=$false)][switch]$SendLogFile,
   [Parameter(Mandatory=$false)][string]$SMTPServer,
   [Parameter(Mandatory=$false)][string]$SMTPSender,
   [Parameter(Mandatory=$false)][string]$SMTPTo
   
)
#Import Modules
Import-Module dataprotectionmanager

#Testing
$LogPublic=$true
#$Checkonly=$true
$SkipHyperV=$true
#$SendLogFile=$True
#$SMTPServer="ExchangeServer01"
#$SMTPSender="DPM_Alerts@techguy.at"
#$SMTPTo="michael@techguy.at"

#Standard Parameters if empty
if (!($DPMServerName)){$DPMServerName=$env:COMPUTERNAME}
if (!($Spandays)){$Spandays="5"}

$Log=@()

#Counter
$DS_ALL=0
$DS_OK=0
$DS_ERROR=0
$DS_HEAL=0
$DS_SKIPHyperV=0

Get-Datasource -DPMServerName  $DPMServerName | Out-Null
$DS=Get-Datasource -DPMServerName  $DPMServerName | where {$_.CurrentProtectionState -eq "Protected"}
$Date=Get-Date -format d ((Get-Date).adddays(-$Spandays))

$Footer="
`r`n
`r`n
Script powered by www.techguy.at
Find more Information at http://www.techguy.at/tag/checklastbackups/
"

#Functions
Function Write-Log ($Text) {
        # Write Log to PS if $LogPublic is Yes
    if ($LogPublic) {
        if ($Text -match "INFO:") {
            Write-Host $Text -ForegroundColor Green
        } elseif ($Text -match "WARNING:") {
            Write-Host $Text -ForegroundColor Yellow
        } elseif ($Text -match "ERROR:") {
            Write-Host $Text -ForegroundColor Red
        } else {
            Write-Host $Text
        }
    }
    return $Text
    
}

Function Query-DSJobs ($DS) {
    # Query DS if there is an active Job
            
    if ((Get-DPMJob -Datasource $DS -Status InProgress | where {$_.JobCategory -notlike "ArchiveFromSC"}).count -ne 0) {
        $Log+=Write-Log "WARNING: There is a running Job for DS:  $DS.Name"
        return $False
    } else {
        $Log+=Write-Log "INFO: No running Jobs for DS:  $DS.Name"
        return $True
    }
}

#Magic
Foreach ($Entry in $DS) 
{
    $DS_ALL++
    $HyperVState=$true
    if ($Entry.ObjectType -eq "Microsoft Hyper-V" -and $SkipHyperV){$HyperVState=$false; $Log+=Write-Log "Warning: Skip HyperV $Entry"; $DS_SKIPHyperV++}
    $RP=Get-RecoveryPoint -Datasource $Entry | Sort-Object BackupTime -Descending
    if ($RP.count -gt 0) 
    {
        $CompareDate=Get-date($RP[0].BackupTime) -format d
        $Span=New-TimeSpan -Start $CompareDate -End $Date
        if ($Span.Days -gt 0) {
            $Log+=Write-Log "Error: $CompareDate, $Date, $Entry"
            $DS_ERROR++
            if ($Entry.State -eq "Invalid")
            {
                if (!($Checkonly) -and ($HyperVState))
                {
                    if (Query-DSJobs $Entry)
                    {
                        Start-DPMDatasourceConsistencyCheck -Datasource $Entry
                        $DS_HEAL++
                    }
                }
            }
            else
            {
                if (!($Checkonly) -and ($HyperVState))
                {
                    if (Query-DSJobs $Entry)
                    {
                        New-RecoveryPoint -Datasource $Entry -Disk -BackupType expressfull –WithDataIntegrityCheck -Verbose
                        $DS_HEAL++
                    }
                }
            }
        } 
        else
        {
            $Log+=Write-Log "Info: $CompareDate, $Date, $Entry"
            $DS_OK++
        }
    } 
    elseif ($RP.count -eq 0)
    {
        $Log+=Write-Log "Error: no Recoverpoint $Entry"
        if (!($Checkonly) -and ($HyperVState))
        {
            if (Query-DSJobs $Entry)
            {
                Start-DPMDatasourceConsistencyCheck -Datasource $Entry
                $DS_HEAL++
            }
        }
    }

}


if ($SendLogfile) 
{

    $StatusReport="
    `r`n
    `r`n
    Checked Datasources: $DS_all
    Datasources OK: $DS_OK
    Datasources with Error: $DS_ERROR
    Datasources healed: $DS_HEAL
    Datasources skiped on HyperV: $DS_SKIPHyperV
    "


    $Mailtext=$Log -join "`r`n"  
    $Mailtext=$Mailtext+ $StatusReport +$Footer
    Send-MailMessage -From $SMTPSender -SmtpServer $SMTPServer -To $SMTPTo -Subject "RP Status from $DPMServerName" -Body $Mailtext  
}

$Mailtext

Some Screenshots

2015-02-28 09_30_08-SEIMI - SVTGSCDPM01 - Royal TS2015-02-28 09_33_47-SEIMI - SVTGSCDPM01 - Royal TS2015-09-01 06_50_05-Microsoft Edge2016-01-19 09_12_12-BaseIT-RTS - DPMSRV.poloaustria.local - Royal TS

TechNet Gallery Download

You can download this Script at the TechNet Gallery: https://gallery.technet.microsoft.com/Check-DPM-for-last-96f12c86

Let me know if you have some Questions.

All my other TechNet Gallery Downloads are here: http://bit.ly/1jrYQoA

PLEASE RATE MY DOWNLOADS AND LET ME KNOW ABOUT YOUR IDEAS FOR THE NEXT VERSION.

Michael Seidl aka Techguy

1 thought on “Check Last Backup, Version 1.3 available”

  1. For some reason, the script seems to bypass “System Protection” (System State, Bare Metal Recovery).

Leave a Comment

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

*

%d bloggers like this: