[PowerShell, PowerCLI] Check for VMs that are not being backuped


Userlevel 7
Badge +7
  • Veeam Legend, Veeam Vanguard
  • 1199 comments

If you do not run VeeamONE, it can be challenging to check if every VM that should be backed up, is really backed up. Therefore I wrote a small PowerShell script. 

Basically this script looks for each VM if there is a restore point for this VM. If not, it gets listed. 

Extra feature: 

  • Script connects to every vCenter that is registered in B&R server.
  • There is a Blocklist included: when VMs should not be backuped, just place their name in the blocklist and they will not be shown in the list. So you can exclude VMs without editing the script.

Notes:

  • CredObject.xml is used for stored, encrypted credentials.
  • Script connects to local B&R server, so it should run there if not changed.

 

# Load Plugin and module
Add-PSSnapin VeeamPSSnapin
Import-Module VMware.VimAutomation.Core

# Configure for multiple vCenter Connections
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope Session -Confirm:$false
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -Confirm:$false

# Connect to local B&R Server
Connect-VBRServer -Server localhost

# Read Credential-File
$WorkingDir = "C:\_install\script\"
$CredObject = Import-Clixml -Path ($WorkingDir + "CredObject.xml")

# Connect to vCenter servers, added to B&R server
Get-VBRServer -Type VC | ForEach-Object {
Connect-VIServer $_.name -Credential $CredObject -ErrorAction Continue
}

# Read VMs in blocklist
$Blocklist = Get-Content -path ($WorkingDir + "Blocklist.txt") -ErrorAction SilentlyContinue | Foreach {$_.TrimEnd()}

# Read all VMs
$VMs = Get-VM | select Name, MemoryGB, PowerState, VMHost, Folder

# Query Veeam Restore Points
$result = @()
$VbrRestore = Get-VBRBackup | Where-Object {$_.jobtype -eq "Backup"} | ForEach-Object {$Jobname = $_.jobname; Write-Output $_;} | Get-VBRRestorePoint | Select-Object vmname, @{n="Jobname"; e={$Jobname}} |Group-Object vmname
$VbrRestore = $VbrRestore | ForEach-Object {$_.Group | Select-Object -first 1}

# Check, if VM on blocklist and a restore point exists
$VMs | ForEach-Object {
if (($_.name -notin $Blocklist) -and ($_.name -notin $VbrRestore.vmname)) {
$result += $_
}
}
$result | ft -AutoSize

# Close connections
Disconnect-VIServer * -Confirm:$false
Disconnect-VBRServer

 


36 comments

Userlevel 7
Badge +7

just a regular vmdk backup.

thank for looking into this. 

I would run the command Get-VBRRestorePoint to see if the restore point is reported.

Userlevel 1

no results on it , interesting 

I get results on other Systems but not this one

 

What is that mean exactly ? 

Userlevel 7
Badge +6

Does this VM have a parent backup job or is it an imported backup? Just a guess from my side, but Get-VBRRestorePoint could possibly only show restorepoints for existing jobs.

Userlevel 7
Badge +7

no results on it , interesting 

I get results on other Systems but not this one

 

What is that mean exactly ? 

Could it be, you changed the name of the VM in the last 1024 days? But also the VM-name is not correct in your query:

 

Userlevel 1

that is just a addition to the name we add in Vsphere , if I try to use that in a query. 

 

The only thing that might have changed would be restore from backup but can’t say for sure. 

Userlevel 7
Badge +7

that is just a addition to the name we add in Vsphere , if I try to use that in a query. 

 

The only thing that might have changed would be restore from backup but can’t say for sure. 

you forgot quotes: Get-VBRRestorePoint -Name “STVP-UT11 Print Server”

Userlevel 1

good point

That shows restore points from the query. 

Those backups are too old for us to be used anyway, I think what I will do is to purge them and set up new one for that box. I don’t see any other servers with this problem. 

 

I realize this might be off topic but is there a script that would get us output of restore points older than x years and purge ones older than specified date or is it all based on configured retention only? 

Userlevel 7
Badge +7

You are right. You have to ask yourself if it is a good idea to define a VM as backed up when the newest restore point is 3 years old. You can add some logic to the script to calculate the age of a each restore point. Then you have to decide how old a restore point can be to take a VM as currently backed up. 

Userlevel 1

I was hoping that Veeam Legend would be kind enough to help us out with that :) 

Been a while but does anyone know how to pick up only VM’s that’s not backed up past day??

The script works great and I have added the email portion to it so we get a nice HTML bodied email with all the VM’s not backing up.

I need this to work on VM’s not backed up past day, any ideas??

 

Thanks in advanced.

Userlevel 7
Badge +7

Been a while but does anyone know how to pick up only VM’s that’s not backed up past day??

The script works great and I have added the email portion to it so we get a nice HTML bodied email with all the VM’s not backing up.

I need this to work on VM’s not backed up past day, any ideas??

 

Thanks in advanced.

Hi Tom! 

Its not that hard to do so. You need to filter retrieved backups by adding an additional filter in the line: $VbrRestore = Get-VBRBackup | Where-Object … to get just backups of the date range you want to have. At the moment I do not have any lab, therefore I cannot post the correct command for that. Please let me know, If you need further help.

Comment