PowerShell script exchange
Post Reply
pesto
Lurker
Posts: 2
Liked: never
Joined: Jan 08, 2020 1:54 pm
Full Name: Petar Stoimirov
Contact:

Backup vApps by separating individual VMs

Post by pesto »

Hi!

We are using the below ps script to automate our vmware backup solution with veeam. However we are looking to enhance it so that it creates a separate backup file for each VM contained in a specific vApp.

Code: Select all

$VMNames = "vMONITORING", "$True"

$HostName = "#####"
$Directory = "####"
$CompressionLevel = "5"
$EnableEncryption = $False
$EncryptionKey = ""
$Retention = "In3days"

Asnp VeeamPSSnapin

$Server = Get-VBRServer -name $HostName
$MesssagyBody = @()

foreach ($VMName in $VMNames) {
  $VM = Find-VBRViEntity -Name $VMName -Server $Server
  # Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
  $EnableQuiescence = $VMName
  
  If ($EnableEncryption)
  {
    $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString)
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
  }
  
  Else 
  {
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
  }
  
  If ($EnableNotification) 
  {
    $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
    $FailedSessions =  $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}
  
  if ($FailedSessions -ne $Null)
  {
    $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
  }
   
  Else
  {
    $MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
  }
  
  }   
}
Using it like this works fine but it creates a single backup file for the whole vApp, whereas we would prefer if we can reference the vApp in $VMNames but get separate files for each VM.

Thanks in advance!
PetrM
Veeam Software
Posts: 3264
Liked: 528 times
Joined: Aug 28, 2013 8:23 am
Full Name: Petr Makarov
Location: Prague, Czech Republic
Contact:

Re: Backup vApps by separating individual VMs

Post by PetrM »

Hi Petar,

Did you enable "Per-VM" option at the level of repository?

Thanks!
pesto
Lurker
Posts: 2
Liked: never
Joined: Jan 08, 2020 1:54 pm
Full Name: Petar Stoimirov
Contact:

Re: Backup vApps by separating individual VMs

Post by pesto »

It seems like this option is only available for the Enterprise edition though. Is there any way to accomplish this via powershell?
Vitaliy S.
VP, Product Management
Posts: 27120
Liked: 2721 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Backup vApps by separating individual VMs

Post by Vitaliy S. »

The alternative to "per-VM chains" would be to use 1 job - 1 VM configuration, and I guess it should be easy to script it. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests