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}})
}
}
}
Thanks in advance!