Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #http://www.sightunseen.org/files/vm_backup_status.ps1
- asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue
- ####################################################################
- # Configuration
- # vCenter server
- $vcenter = "vcenter.yourdomain.com"
- # To Exclude VMs from report add VM names to be excluded as follows
- $excludevms=@("")
- ### reset variables for debugging only
- $backups_with_errors = $nul
- $number_of_backups_with_errors = $nul
- $failedbackups = $nul
- $backups_with_errors = $nul
- $numberofprotectedvms = $nul
- $vms=""
- ####################################################################
- $vcenterobj = Get-VBRServer -Name $vcenter
- $backups_with_errors = $nul
- # Build hash table with excluded VMs
- $excludedvms=@{}
- foreach ($vm in $excludevms) {
- $excludedvms.Add($vm, "Excluded")
- }
- # Get a list of all VMs from vCenter and add to hash table, assume Unprotected
- $vms=@{}
- # only monitor those VMs on Production. To monitor all VMs registered on vCenter, just remove the and -match
- foreach ($vm in (Find-VBRObject -Server $vcenterobj -WarningAction "SilentlyContinue" | Where-Object {$_.Type -eq "VirtualMachine" -and $_.Datastores -match "DATASTORE_PRODUCTION" })) {
- if (!($excludedvms.ContainsKey($vm.Name) -or $vms.ContainsKey($vm.Name))) {
- $vms.Add($vm.Name, "Unprotected")
- }
- }
- # Find all backup job sessions that have ended in the last 24 hours
- $vbrsessions = Get-VBRBackupSession | Where-Object {$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).addhours(-24)}
- # Find all successfully backed up VMs in selected sessions (i.e. VMs not ending in failure) and update status to "Protected"
- foreach ($session in $vbrsessions) {
- foreach ($vm in ($session.gettasksessions() | Where-Object {$_.Status -ne "Failed"} | ForEach-Object { $_ })) {
- if($vms.ContainsKey($vm.Name)) {
- $vms[$vm.Name]="Protected"
- }
- }
- }
- #$failedbackups=""
- #$number_of_backups_with_errors = 0
- # Output VMs in color coded format based on status.
- foreach ($vm in $vms.Keys)
- {
- if ($vms[$vm] -eq "Protected") {
- #write-host -foregroundcolor green "$vm is backed up"
- } else {
- #write-host -foregroundcolor red "$vm is NOT backed up"
- $backups_with_errors = $true
- $failedbackups=$failedbackups+":"+$vm
- $number_of_backups_with_errors = $number_of_backups_with_errors+1
- }
- }
- if ($backups_with_errors -eq $false){
- $numberofprotectedvms = (Get-VBRRestorePoint | select {$_.VmName} -uniq).Count
- Write-Host "OK: $numberofprotectedvms VMs are protected with Veeam"
- exit 0
- } else {
- if ($number_of_backups_with_errors -eq $nul)
- {Write-Host "No failed backups on DATASTORE_PRODUCTION."
- exit 0
- } else {
- Write-Host "$number_of_backups_with_errors missing Veeam Backups $failedbackups"
- }
- exit 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement