Bellow is a script to get Free Veeam Backup and replication to schedule a VeamZip backup.
# Author: Vladimir Eremin
# Created Date: 3/24/2015
# http://forums.veeam.com/member31097.html
#Edited by Roger Saffle 3/13/2018 to update some variables problems and mail sending
##################################################################
# User Defined Variables
##################################################################
# Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”
$VMNames = “VM_GUEST_TO_BACKUP“
# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
# THIS NEED TO BE THE NAME ON THE VEEAM MACHINE NOT THE NAME IN HYPERV MANAGER
$HostName = “VM_HOST”
# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = “C:\Backup”
# Desired compression level (Optional; Possible values: 0 – None, 4 – Dedupe-friendly, 5 – Optimal, 6 – High, 9 – Extreme)
$CompressionLevel = “5”
# Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
$EnableQuiescence = $True
# Protect resulting backup with encryption key (Optional; $True/$False)
$EnableEncryption = $False
# Encryption Key (Optional; path to a secure string)
$EncryptionKey = “”
# Retention settings (Optional; By default, VeeamZIP files are not removed and kept in the specified location for an indefinite period of time.
# Possible values: Never , Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month)
$Retention = “Never”
##################################################################
# Notification Settings
##################################################################
# Enable notification (Optional)
$EnableNotification = $True
# Email SMTP server
$SMTPServer = “SMPT.SERVER”
# Email FROM
$EmailFrom = “Veeam_BU@domain.com”
# Email TO
$EmailTo = “admin@domain.com”,”admin2@domain.com”
# Email subject
$EmailSubject = “Subject”
##################################################################
# Email formatting
##################################################################
$style = “<style>BODY{font-family: Arial; font-size: 10pt;}”
$style = $style + “TABLE{border: 1px solid black; border-collapse: collapse;}”
$style = $style + “TH{border: 1px solid black; background: #dddddd; padding: 5px; }”
$style = $style + “TD{border: 1px solid black; padding: 5px; }”
$style = $style + “</style>”
##################################################################
# End User Defined Variables
##################################################################
#################### DO NOT MODIFY PAST THIS LINE ################
Asnp VeeamPSSnapin
$Server = Get-VBRServer -name $HostName
$MesssagyBody = @()
# CHANGE $VM= VALUE BELLOW Find-VBRHvEntity FOR HYPERV OR Find-VBRViEntity FOR VMWARE
foreach ($VMName in $VMNames)
{
$VM = Find-VBRHvEntity -Name $VMName -Server $Server
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 = ($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}})
}
}
}
If ($EnableNotification)
{
$body = $MesssagyBody | Out-String
Send-MailMessage -from $EmailFrom -To $EmailTo -Subject $EmailSubject -smtpServer $SMTPServer -Body $Body