PowerShell script exchange
Post Reply
billcouper
Service Provider
Posts: 153
Liked: 34 times
Joined: Dec 18, 2017 8:58 am
Full Name: Bill Couper
Contact:

SureBackup v11 PowerShell issues

Post by billcouper »

Hi. I am trying to create a 'dynamic' surebackup verification job using a script. The environment does not have enough available memory to run all VM's in surebackup. This will run surebackup against a limited number of VM's once per week, rotating through the entire list of VM's over time until they are all verified, then starting again on the second round of verifications per VM.

The script should find primary 'backup' jobs run within 30 days. It should find the VM's that were backed up by those jobs. It should check SureBackup sessions to find the last time each VM was verified using SureBackup. It should pick the two VM's that have gone the longest without being run through SureBackup. It should then create the app group and the surebackup job, run the job, and clean up after itself. The next time the script runs (week 2), those two VM's verified in the first week will show a recent verification date, so other different VM's will be picked.

The problem I am having is with the "Add-VBRViApplicationGroup" cmdlet and the requirement to use New-VBRSureBackupVM to pass it the list of VM's.

Here is a cut-down example of the script for consideration...

Code: Select all

# Variables
$AppGroupName = "Dynamic App Group"
$SbJobName = "Dynamic Surebackup Job"
$SbJobDesc = "Dynamic App Testing"
$VirtualLab = "Virtual Lab 1"
[int]$NumberofVMs = 2
[int]$CheckBackupsNewerThanDays = 30

# Populate these arrays
$JobList = @()
$VmList = @()

# Populate $JobList
foreach ($vbrRecentJob in Get-VBRJob | ? { $_.IsBackup -and $_.LatestRunLocal -gt (get-date).AddDays(-$CheckBackupsNewerThanDays) }) {
    $objJob = [pscustomobject]@{
        Name = $vbrRecentJob.Name
        LastRun = $vbrRecentJob.LatestRunLocal
    }
    $JobList += $objJob
}

# Populate $VmList
foreach ($job in $JobList | sort LastRun -Descending) {
    $VbrJob = Get-VBRJob -Name $job.Name
    foreach ($vm in Get-VBRTaskSession -Session $VbrJob.FindLastSession()) {
        $objVM = [pscustomobject]@{
            Name = $vm.Name
            Job = $job.Name
            LastVerify = ''
        }
        $VmList += $objVM
    }
}

# Update the $VmList 'LastVerify' property of each VM
foreach ($VsbSession in get-vsbsession | sort CreationTime) {
    foreach ($TaskSession in $VsbSession.GetTaskSessions()) {
        if ($Match = $VmList | ? { $_.Name -eq $TaskSession.Name }) {
            $Match.LastVerify = $VsbSession.CreationTime
        }
    }
}

# Create and run the SureBackup job (using existing lab name defined in $VirtualLab)
$TestVMs = $VmList | sort LastVerify | select -first $NumberofVMs
$VirtualLab = Get-VBRVirtualLab -Name $VirtualLab -Verbose
$backupobjects = @()
foreach ($testvm in $TestVMs) {
      $backupobjects += New-VBRSureBackupVM -VM (Get-VBRJobObject -Job $testvm.Job -Name $testvm.Name)
}
$AppGroup = Add-VBRViApplicationGroup -VM (New-VBRSureBackupVM -VM $backupobjects) -Name $AppGroupName -Description $SbJobDesc -Verbose
$VsbJob = Add-VBRViSureBackupJob -VirtualLab $VirtualLab -ApplicationGroup $AppGroup -Description $SbJobDesc -Verbose
Start-VSBJob -Job $VsbJob -Verbose
Remove-VSBJob -Job $VsbJob -Confirm:$false -Verbose
Remove-VBRApplicationGroup -ApplicationGroup $AppGroup -Confirm:$false -Verbose
I have tried creating an array of 'New-VBRSureBackupVM' objects to pass to Add-VBRViApplicationGroup -VM $array.
I have tried creating the app group using each individual VM from the 'New-VBRSureBackupVM' output and using Set-VBRViApplicationGroup to add the second/subsequent vm's.
I have tried creating an array of 'FindVBRViEntity' objects to pass to Add-VSBViApplicationGroup (deprecated cmdlet).

Another issue is that the combination of Get-VBRJobObject with New-VBRSureBackupVM doesn't seem to work as documented.
For example, consider this sample code

Code: Select all

$testvm = [pscustomobject]@{
    Job = 'Job Name'
    Name = 'VM Name'
}
Get-VBRJobObject -Job $testvm.Job -Name $testvm.Name
New-VBRSureBackupVM -VM (Get-VBRJobObject -Job $testvm.Job -Name $testvm.Name)
The 'Get-VBRJobObject' returns a job object as expected, however when I try to create the New-VBRSureBackupVM object I get this error:

Code: Select all

New-VBRSureBackupVM : Cannot find the specified backup object 2c764a94-821f-49c8-b54c-3424345955ee in the selecte job cd34c8b2-866b-425a-9f88-7ed3f323098d.
At line:1 char:1
+ New-VBRSureBackupVM -VM (Get-VBRJobObject -Job $testvm.Job -Name $tes ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-VBRSureBackupVM], Exception
    + FullyQualifiedErrorId : ParameterSetId,Veeam.Backup.PowerShell.Cmdlets.NewVBRSureBackupVM
If the Get-VBRJobObject returns an object, doesn't that indicate that it exists in the backup job?
billcouper
Service Provider
Posts: 153
Liked: 34 times
Joined: Dec 18, 2017 8:58 am
Full Name: Bill Couper
Contact:

Re: SureBackup v11 PowerShell issues

Post by billcouper »

Examples of the data in the arrays where I collected the data:

$JobList

Code: Select all

Name                         LastRun              
----                         -------              
Daily  Backup                12/07/2021 5:00:18 PM
Daily Backup - Low Retention 12/07/2021 6:00:01 PM
$VmList

Code: Select all

Name          Job                          LastVerify            
----          ---                          ----------            
SJA-DWN-WS01  Daily Backup - Low Retention 13/01/2021 8:55:41 AM 
SJA-CAS-XD01  Daily Backup - Low Retention 28/05/2021 11:30:44 AM
SJA-DWN-VC02  Daily Backup - Low Retention                       
SJA-CAS-PH01  Daily Backup - Low Retention 16/04/2021 11:30:33 AM
SJA-CAS-CCTV  Daily Backup - Low Retention 12/02/2021 11:30:29 AM
SJA-CAS-IM01  Daily Backup - Low Retention 11/06/2021 11:30:44 AM
SJA-CAS-LB01  Daily Backup - Low Retention 26/03/2021 11:30:34 AM
SJA-CAS-RPA01 Daily Backup - Low Retention 30/04/2021 11:30:35 AM
SJA-CAS-MS01  Daily Backup - Low Retention 2/04/2021 11:30:52 AM 
SJA-CAS-NP01  Daily Backup - Low Retention 9/04/2021 11:30:30 AM 
SJA-CAS-PW01  Daily Backup - Low Retention 18/06/2021 11:30:35 AM
SJA-CAS-RP01  Daily Backup - Low Retention 23/04/2021 11:31:33 AM
SJA-CAS-XA00  Daily Backup - Low Retention 21/05/2021 11:30:35 AM
SJA-CAS-EX01  Daily  Backup                5/03/2021 11:30:32 AM 
SJA-CAS-DB01  Daily  Backup                19/02/2021 11:30:29 AM
SJA-DWN-DB01  Daily  Backup                4/06/2021 11:30:36 AM 
SJA-CAS-DC01  Daily  Backup                2/10/2020 11:30:30 AM 
SJA-CAS-FS01  Daily  Backup                19/03/2021 11:30:31 AM
SJA-CAS-AP02  Daily  Backup                5/02/2021 11:30:53 AM 
SJA-CAS-AP01  Daily  Backup                29/01/2021 11:30:54 AM
billcouper
Service Provider
Posts: 153
Liked: 34 times
Joined: Dec 18, 2017 8:58 am
Full Name: Bill Couper
Contact:

Re: SureBackup v11 PowerShell issues

Post by billcouper »

I made a mistake when copy/pasting my sample code as I was re-combining multiple versions I had tried and failed... I can't edit that post for whatever reason

The line that reads:

Code: Select all

$AppGroup = Add-VBRViApplicationGroup -VM (New-VBRSureBackupVM -VM $backupobjects) -Name $AppGroupName -Description $SbJobDesc -Verbose
Should actually be:

Code: Select all

$AppGroup = Add-VBRViApplicationGroup -VM $backupobjects -Name $AppGroupName -Description $SbJobDesc -Verbose
billcouper
Service Provider
Posts: 153
Liked: 34 times
Joined: Dec 18, 2017 8:58 am
Full Name: Bill Couper
Contact:

Re: SureBackup v11 PowerShell issues

Post by billcouper »

Yeah..... this is all broken as far as I can tell..... can someone from Veeam please provide some insight into this behavior?

I am doing this for a rental customer and need to get a solution....

The customer has two backup jobs.

---[ Job #1 ]---------------------------------------------------------------------------------------

1. One job is named "Daily Backup - Low Retention".
1a. The backup job targets a resource pool in vSphere
1b. The backup job has a list of excluded disks
1c. One of the VM's that the job actually backs up is named SJA-CAS-MS01

This command works. I get a $job object that represents the backup job "Daily Backup - Low Retention" as expected:

Code: Select all

$job = Get-VBRJob -Name "Daily Backup - Low Retention"
This command works. I get a $backupobject that represents the VM backed up by the job:

Code: Select all

$backupobject = Get-VBRJobObject -Job $job -Name "SJA-CAS-MS01"
This command does not work. I get an error message:

Code: Select all

New-VBRSureBackupVM -vm $backupobject
New-VBRSureBackupVM : Cannot find the specified backup object 280de6f3-7f38-4732-81f7-2837a0c78a18 in the selecte job cd34c8b2-866b-425a-9f88-7ed3f323098d.
At line:1 char:1
+ New-VBRSureBackupVM -vm $backupobject
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-VBRSureBackupVM], Exception
    + FullyQualifiedErrorId : ParameterSetId,Veeam.Backup.PowerShell.Cmdlets.NewVBRSureBackupVM
---[ Job #2 ]---------------------------------------------------------------------------------------

2. The other job is named "Daily Backup" (with two spaces, I don't know why, assume typo).
2a. The backup job targets a resource pool in vSphere
2b. The backup job has a list of excluded virtual machines, as well as a list of excluded disks
2c. One of the VM's that the job actually backs up is named SJA-CAS-DC01

This command works. I get a $job object that represents the backup job "Daily Backup" as expected:

Code: Select all

$job = Get-VBRJob -Name "Daily  Backup"
This command does not work. I do not get a $backupobject at all. There is no error, just nothing is returned:

Code: Select all

$backupobject = Get-VBRJobObject -Job $job -Name "SJA-CAS-DC01"
billcouper
Service Provider
Posts: 153
Liked: 34 times
Joined: Dec 18, 2017 8:58 am
Full Name: Bill Couper
Contact:

Re: SureBackup v11 PowerShell issues

Post by billcouper »

Support Case #04917181
soncscy
Veteran
Posts: 643
Liked: 312 times
Joined: Aug 04, 2019 2:57 pm
Full Name: Harvey
Contact:

Re: SureBackup v11 PowerShell issues

Post by soncscy »

Hey Bill,

This must be environment specific, cause I just ran through your tooling in my own environment and it was fine.

Since you can see the VMObject in question having issues get its ID + the associated JobID returned on the object itself (from $backupObject, try the properties ID and JobID and first see what's returned, then check the output of GetObject())

Then, you can compare the results of the method GetObjectsinJob() on the Job Object returned by Get-VBRJob.

I think it has to be something there that's mismatched. Maybe you need to remove and re-add this VM to the job?
oleg.feoktistov
Veeam Software
Posts: 2007
Liked: 666 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: SureBackup v11 PowerShell issues

Post by oleg.feoktistov »

Hi Bill,

Can you tell me of which type is the job object you are trying to pass to New-VBRSureBackupVM cmdlet looking into the property below?

Code: Select all

$object = Get-VBRJobObject -Job $job
$object.Type
If it is of Exclude type, then the error makes sense. As far as I see in the source code of New-VBRSureBackupVM cmdlet, only job objects of Include type are accepted.

Looking forward to your reply.

Thanks,
Oleg
billcouper
Service Provider
Posts: 153
Liked: 34 times
Joined: Dec 18, 2017 8:58 am
Full Name: Bill Couper
Contact:

Re: SureBackup v11 PowerShell issues

Post by billcouper »

The backup job 'Source' is targeted to a resource pool in vSphere.

For the job that returns a "job object" the type is ExcludeDisksChild.

It is now obvious that these commands will only work if every individual VM is listed as an included object in the job 'Source' screen. From what I have seen across our customer base, this is a very uncommon scenario. 99% of all setups I have seen will target either a resource pool, or a VM folder. I don't see customers adding a list of VM's to jobs individually.
oleg.feoktistov
Veeam Software
Posts: 2007
Liked: 666 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: SureBackup v11 PowerShell issues

Post by oleg.feoktistov »

Yes, it makes perfect sense to me. What we are figuring out is an adjustment to New-VBRSureBackupVM cmdlet so that it could accept job includes other than of VM type. Thanks!
billcouper
Service Provider
Posts: 153
Liked: 34 times
Joined: Dec 18, 2017 8:58 am
Full Name: Bill Couper
Contact:

Re: SureBackup v11 PowerShell issues

Post by billcouper »

I modified this customers backup jobs to explicitly list every VM to be backed up.

It does work, but there is still one issue. If a VM has a disk exclusion, there are two "job objects" returned. One for include, one for disk exclusion. This seems to randomly throw the New-VBRSureBackupVM for a spin - sometimes it will work, other times it will say the object type is wrong. I had to limit the job object to the Include type before passing it to the cmdlet.

The need to explicitly list every VM, then getting confused when there are disk exclusions, seems like design flaws in the cmdlets that I hope can be rectified.

Edit: to be perfectly clear, I would expect to be able to use a logical grouping of VM's as the source of the job (such as a Resource Pool, VM Folder, Tag, etc) as well as being able to specify disk exclusions, and I would expect the cmdlets to handle such job configurations without errors.
oleg.feoktistov
Veeam Software
Posts: 2007
Liked: 666 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: SureBackup v11 PowerShell issues

Post by oleg.feoktistov »

Agree with you. Logical grouping is the main feature we are considering for this cmdlet. We might need to choose a different entry point though as a separate parameter for each container entity looks redundant in this case. As for the exclusion handling - a good one! Added it as a point of discussion also. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests