PowerShell script exchange
Post Reply
masonit
Service Provider
Posts: 327
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Find vms in backups, that are no longer included in job

Post by masonit »

Hi

As the subjects says. When you remove a vm from a backup job. The vms backup data is still in backups. I want to find all thoose vm backups that are "orphaned" like that. Combining data from cmdlets like get-vbrjob, get-vbrjobobjects and Get-VBRBackup would be possible. But maybe there is a smarter way, like a method for this..?

\Masonit
HannesK
Product Manager
Posts: 14844
Liked: 3086 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: Find vms in backups, that are no longer included in job

Post by HannesK »

Hello,
I don't have an answer to your question, but in case you want to delete "The vms backup data is still in backups"... there is a checkbox for that to automatically remove orphaned VMs from backup after a specific time.

Best regards,
Hannes
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Find vms in backups, that are no longer included in job

Post by veremin »

Two recommendations:

1) Set deleted VM retention period
2) Check backup job session (either in UI or in PS) for special string: "VMName is no longer processed" (or similar). The string indicates "orphaned" VMs.

Thanks!
Vek17
Service Provider
Posts: 49
Liked: 15 times
Joined: May 29, 2018 8:42 pm
Contact:

Re: Find vms in backups, that are no longer included in job

Post by Vek17 » 1 person likes this post

By far the easiest way here is just grabbing the backup (Get-VBRBackup) and then grabbing the restore points in that backup (Get-VBRRestorePoints). This will return all the OIB data you need to view this and tell you how old this data is. Both ObjectID and VmName are present in this data to identify objects.

If you want to compare that against what objects are in the active job you are going to need to do something like this to get the active VMs:

Code: Select all

$ActiveVMsMap           = @{}
if(!$ActiveVMsMap.Contains($Job.ID)){
    $ActiveVMsMap.Add($Job.ID, @())
}
$ActiveVMsMap[$Job.Id] += $Job.getObjectsInJob() | Where-Object {$_.Type -ne "Exclude" -and $_.Type -ne "VSSChild"} | Select-Object -ExpandProperty name
foreach ($Id in $Job.LinkedJobIds.Guid){
    $ActiveVMsMap[$Job.Id] += ([Veeam.Backup.Core.CBackupJob]::GetAll()| Where-Object {$_.id -eq $Id}).getObjectsInJob() | Where-Object {$_.Type -ne "Exclude" -and $_.Type -ne "VSSChild"} | Select-Object -ExpandProperty name
}
forEach($object in $Job.getObjectsInJob() | Where-Object {$_.GetObject().Type -eq "Host"} | Select-Object -ExpandProperty name){
    $ActiveVMsMap[$Job.ID] += Get-VBRServer -Name $object | Find-VBRViEntity | Where-Object type -eq VM | Select-Object -ExpandProperty name | Where-Object {($Job.GetObjectsInJob() | Where-Object type -eq exclude).name -notcontains $_ }
    $ActiveVMsMap[$Job.ID] += Get-VBRServer -Name $object | Find-VBRHvEntity | Where-Object type -eq VM | Select-Object -ExpandProperty name | Where-Object {($Job.GetObjectsInJob() | Where-Object type -eq exclude).name -notcontains $_ }
}
if($Job.JobType -eq "EndpointBackup"){
    $ActiveVMsMap[$Job.ID] += $job.FindLastBackup().GetLastPoint().GetOibs().VmName
}
masonit
Service Provider
Posts: 327
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Find vms in backups, that are no longer included in job

Post by masonit »

Hi

Deleted vm retention period is active.

@Vek17, Thanks, will take a look!

\Masonit
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests