PowerShell script exchange
Post Reply
acovello
Lurker
Posts: 1
Liked: never
Joined: Apr 09, 2019 10:09 pm
Full Name: Abe Covello

Looking for help with exporting restore point for all VMs in a backup job

Post by acovello »

I am looking for some help with a PowerShelll script we're trying to use to export Restore Points out to a USB drive, and keep getting errors.

Code: Select all

Add-PSSnapin VeeamPSSnapin

$Jobs = Get-VBRJob -name "DC_Test"
#$Jobs = Get-VBRBackup -name "DC_Test"

foreach ($Job in $Jobs) {
Write-Host "Job: " -NonewLine
echo $Job.name
#Skip if Job is Disabled
if (! $job.info.IsScheduleEnabled) {
echo "Skipping disabled job..."
echo ""
continue
}

 $vms = $job.GetObjectsInJob()
  foreach ($vm in $vms) {
    Write-Host "VM: " -NonewLine
    echo $vm.Name
    $rp = Get-VBRRestorePoint -Name $vm.name | Sort-Object -Property CreationTime -Descending | Select -First 1
    Write-Host "RP Creation Time: " -NoNewLine
    echo $rp.CreationTime
    echo "Exporting backup to file..."
    #echo $rp
    Export-VBRBackup -RestorePoint $rp -Dir "C:\Export"
    }
    echo ""
    }
This job contains two systems (Domain controllers for testing). The first VM exports fine, but the second thriws an error because the VIB file already exists.

Code: Select all

Export-VBRBackup : The file 'C:\Export\DC_TestD2019-04-10T160035_84FF.vib' already exists.
At C:\Veeam export script\Exportv2.ps1:25 char:5
+     Export-VBRBackup -RestorePoint $rp -Dir "C:\Export"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Export-VBRBackup], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Veeam.Backup.PowerShell.Cmdlets.ExportVBRBackup
Is there a way to rename the output for each VM, or have it write to a folder dependant on the VM name?
Or am I going about this all wrong?
jhoughes
Veeam Vanguard
Posts: 282
Liked: 113 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Looking for help with exporting restore point for all VMs in a backup job

Post by jhoughes »

I’m assuming that you have 2 VMs in the backup job, but you are backing up to a repository which is NOT leveraging per-VM backup chains, correct?

If that is the case, you would only have a single restore point for every run of the job, regardless of how many VMs are within the job, so you would not want to run your loop as per-VM, as that is not how the data is contained in the repository.

Basically, your loop would be per restore point, rather than per VM. The number of restore points would be the number of objects to iterate through in your for each loop, since that is the number of objects, rather than the number of VMs.
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Looking for help with exporting restore point for all VMs in a backup job

Post by veremin »

Also, be aware that Export-VBRBackup is an old cmdlet that doesn't export restore point, as this function does, instead it copies backup files to the selected location. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests