internet archive got you covered
One of the common report request that comes up on the Veeam forums is a method to report which VMs in the environment are being properly backed up. Currently Veeam has no built in report to compare the VMs in your environment to the VMs that are currently in your backup job, and while comparing this list is pretty easy if you have 20-30 VMs, it can quickly become a challenge as the environment gets larger and becomes more dynamic. This is my attempt to address the situation and learn some Powershell at the same time.
This script finds all VMs on a single vCenter server and looks through all Backup job sessions in the defined time period (currently 24 hours) and reports if they were successfully backed up or not.
The current “stable” version of this script can be downloaded here (7/3/2012). This version has to following limitations:
Tested only on vCenter/VMware environments
Duplicate VM names trip it up
Supports only a single vCenter at a time.
The current “development” version of this script is available here (7/30/2012). The primary enhancements of the development version when compared to the “stable” version are as follows:
Proper handling of VMs with duplicate names in different datacenters
VMs missing from jobs are listed first in the script output
VMs that are found in backups also display Job Name in which they are found
Simple wildcards are now support for exclusion list (for example *_replica to exlcude replica VMs)
Parameter to define length of history to look for VMs in backup jobs (default 24 hours).
Code: Select all
asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue
####################################################################
# Configuration
#
# vCenter server
$vcenter = "vc01.notyourdomain.com"
#
# To Exclude VMs from report add VM names to be excluded as follows
# simple wildcards are supported:
# $excludevms=@("vm1","vm2", "*_replica")
$excludevms = @()
#
# This variable sets the number of hours of session history to
# search for a successul backup of a VM before considering a VM
# "Unprotected". For example, the default of "24" tells the script
# to search for all successful/warning session in the last 24 hours
# and if a VM is not found then assume that VM is "unprotected".
$HourstoCheck = 24
####################################################################
$vcenterobj = Get-VBRServer -Name $vcenter
$vmobjs = Find-VBRObject -Server $vcenterobj | Where-Object {$_.Type -eq "VirtualMachine"}
$jobobjids = [Veeam.Backup.Core.CHierarchyObj]::GetObjectsOnHost($vcenterobj.id) | Where-Object {$_.GetItem().Type -eq "Vm"}
# Convert exclusion list to simple regular expression
$excludevms_regex = (‘(?i)^(‘ + (($excludevms | ForEach {[regex]::escape($_)}) –join “|”) + ‘)$’) -replace "\\\*", ".*"
foreach ($vm in $vmobjs) {
$jobobjid = ($jobobjids | Where-Object {$_.ObjectId -eq $vm.Id}).Id
if (!$jobobjid) {
$jobobjid = $vm.FindParent("Datacenter").Id + "\" + $vm.Id
}
$vm | Add-Member -MemberType NoteProperty "JobObjId" -Value $jobobjid
}
# Get a list of all VMs from vCenter and add to hash table, assume Unprotected
$vms=@{}
foreach ($vm in ($vmobjs | where {$_.Name -notmatch $excludevms_regex})) {
if(!$vms.ContainsKey($vm.JobObjId)) {
$vms.Add($vm.JobObjId, @("!", [string]$vm.GetParent("Datacenter"), $vm.Name))
}
}
# Find all backup job sessions that have ended in the last 24 hours
$vbrjobs = Get-VBRJob | Where-Object {$_.JobType -eq "Backup"}
$vbrsessions = Get-VBRBackupSession | Where-Object {$_.JobType -eq "Backup" -and $_.EndTime -ge (Get-Date).addhours(-$HourstoCheck)}
if (!$vbrsessions) {
write-host "No backup sessions found in last" $HourstoCheck "Hours!"
exit
}
# 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.Info.ObjectId)) {
$vms[$vm.Info.ObjectId][0]=$session.JobName
}
}
}
$vms = $vms.GetEnumerator() | Sort-Object Value
# Output VMs in color coded format based on status.
foreach ($vm in $vms)
{
if ($vm.Value[0] -ne "!") {
write-host -foregroundcolor green (($vm.Value[1]) + "\" + ($vm.Value[2])) "is backed up in job:" $vm.Value[0]
} else {
write-host -foregroundcolor red (($vm.Value[1]) + "\" + ($vm.Value[2])) "is not found in any backup session in the last" $HourstoCheck "hours"
}
}
before trying it out, I would definitely go through the script, review the command used and validate
don't blindly run an 8 year old PS script on your 2020 env
and that blog points to another blog
https://blog.smasterson.com/2017/12/22/ ... ort-9-5-3/
which has some nice script too;
down the internet rabbit hole we go