Creating backups for VMs based on vCloud Director

PowerShell script exchange

Creating backups for VMs based on vCloud Director

Veeam Logoby vmm » Thu May 12, 2016 12:13 pm

Hi!

We encountered two problems while:
1) creating backups for virtual machines using the same name based on vCloud Director
2) trying to restore virtual machines from backup based on vCloud Director

1) While trying to create backup for a VM deployed in vApp in vCloud Director using PowerShell everything works when the VM name is unique:

Code: Select all
param([string]$vm_name,[string]$index)

Add-PSSnapin VeeamPSSnapin
$vmcloud = Find-VBRvCloudEntity -Name "$vm_name"
$repository = Get-VBRBackupRepository -Name "Backup Repository 1"
Add-VBRvCloudJob -Name "$($vm_name)_$($index)" -Entity $vmcloud -BackupRepository $repository
Get-VBRJob -Name "$($vm_name)_$($index)" | Set-VBRJobAdvancedBackupOptions -Algorithm ReverseIncremental
Get-VBRJob -Name "$($vm_name)_$($index)" | Set-VBRJobAdvancedOptions -RetainDays 14
Get-VBRJob -Name "$($vm_name)_$($index)" | Set-VBRJobAdvancedViOptions -VMToolsQuiesce $True
$Job = Get-VBRJob -Name "$($vm_name)_$($index)"
$Job.BackupStorageOptions.EnableDeletedVmDataRetention = $true
$Options = $Job.GetOptions()
$Options.SanIntegrationOptions.FailoverFromSan = $True
$Options.BackupStorageOptions.StgBlockSize = "KbBlockSize512"
$Options.BackupStorageOptions.RetainCycles = 1

$Job.SetOptions($Options)
Get-VBRJob -Name "$($vm_name)_$($index)" | Start-VBRJob -runasync
Write-Host "Done!"


But when the VM name is the same with other VM in vCloud Director (which is possible because you can have a lot of organizations, vApps for clients and for sure VM name can be the same created by clients) we get an error and failed job, even duplicate ones.

2) While trying to restore a VM from backup to vCloud Director (not vApp but VM) the restore fails because it cannot find a restore point. Strangely when you look at restore point for VM using PowerShell it shows vApp's name as vm's name:

Code: Select all
param([string]$vm_name,[string]$index)

Add-PSSnapin VeeamPSSnapin
$restorepoint = Get-VBRBackup -Name "$($vm_name)_$($index)" | Get-VBRRestorePoint -Name * | Sort-Object $_.creationtime -Descending | Select -First 1
Start-VBRvCloudRestoreVm -RestorePoint $restorepoint -PowerUp -RunAsync
Write-Host "Done!"
vmm
Service Provider
 
Posts: 15
Liked: never
Joined: Mon Nov 23, 2015 10:09 am
Full Name: Marat Akhmetianov

Re: Creating backups for VMs based on vCloud Director

Veeam Logoby vmm » Fri May 13, 2016 12:21 pm

While trying to create backup using PowerShell script I get an error as the entity is empty. Here is the code:

param([string]$vm,[string]$vcd,[string]$org,[string]$orgvdc,[string]$vapp,[string]$index)

Add-PSSnapin VeeamPSSnapin
$vmcloud = Find-VBRvCloudEntity -Name "$vm" | Where Path -eq "$($vcd)\$($org)\$($orgvdc)\$($vapp)\$($vm)"
$repository = Get-VBRBackupRepository -Name "Backup Repository 1"
Add-VBRvCloudJob -Name "$($vm)_$($index)" -Entity $vmcloud -BackupRepository $repository
Write-Host "Done!"

Here is the command to launch a script:
.\cloud_create_backup3.ps1 -vm vcloud_VM_2 vcd 10.12.0.171 -org Test-Org02 -orgvdc Test-Org02-vDC -vapp -vApp_TEST1 -index 333

If I use commands everyting works:
$cloud = Find-VBRvCloudEntity -Name "vcloud_VM_2" | Where Path -eq "10.12.0.171\Test-Org02\Test-Org02-vDC\vApp_TEST1\vcloud_VM_2"
$repository = Get-VBRBackupRepository -Name "Backup Repository 1"
Add-VBRvCloudJob -Name "vcloud_VM3333" -Entity $cloud -BackupRepository $repository

Support Case Number: ID# 01797486
vmm
Service Provider
 
Posts: 15
Liked: never
Joined: Mon Nov 23, 2015 10:09 am
Full Name: Marat Akhmetianov

Re: Creating backups for VMs based on vCloud Director

Veeam Logoby v.Eremin » Tue May 17, 2016 3:10 pm

Can you catch the result of "$($vcd)\$($org)\$($orgvdc)\$($vapp)\$($vm)" and see whether it returns meaningful data? Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 4 guests