Veeam Backup and Replication has a lot to offer for a disaster recovery solution and is easily my favorite tool to use for virtual backups. However, if you are using the free edition and VeeamZIP to get those backups completed you will be forced to complete the task yourself. After running into this problem you may have already found a way to fix this, or you may still be searching for a solution.

 

Automating the Issue

The main thing that was made available to fix this issue with the free edition of Veeam was the PowerShell cmdlet Start-VBRZip. VeeamZip is similar to the full VM backup in that it always produces a full backup file (.VBK file) that may be used as a restore point. This can then be sent to a backup repository, local folder, or a network share. With at least Powershell 3.0 and Veeam Backup Free Edition v8 Update 2 (currently v9), you can access the cmdlets needed to write a script to automate your virtual backups. The following script will trigger the backup as well as email you a report of your backup job status.

 

Let’s Get You Backed Up.ps1

This script allows for backups of any VMs that exist on your vCenter with all the same settings you would be asked for in the GUI of Veeam. You are required to fill out the VM names, vCenter IP/DNS name, and the directory that the backups will be targeted at.

# VM names separated by commas
$VMNames = “VM1”, “VM1”

# vCenter name/IP
$HostName = “10.30.10.140”

# Directory that VM backups should go to
$Directory = “\\10.30.10.85\Veeam”

# Desired compression level, following compression level from Veeam (Optional)
$CompressionLevel = “4”

# 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, C:\SecureString.txt”
$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 = “In3days”

# Email Settings

# Enable notification (Optional)
$EnableNotification = $True

# Email SMTP server
$SMTPServer = “smtp.smtp.com”

# Email FROM
$EmailFrom = “sender@cnwr.com”

# Email TO
$EmailTo = “recipient@cnwr.com”

# Email subject
$EmailSubject = “Veeam Backup Job”
# 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: #54b948; 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
$mbody = @()

foreach ($VMName in $VMNames)
{
$VM = Find-VBRViEntity -Name $VMName -Server $Server
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention

If ($EnableNotification)
{
$TaskSessions = $ZIPSession.GetTaskSessions()
$FailedSessions = $TaskSessions | where {$_.status -eq “EWarning” -or $_.Status -eq “EFailed”}

if ($FailedSessions -ne $Null)
{
$mbody = $mbody + ($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
{
$mbody = $mbody + ($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)
{
$Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
$Message.Subject = $EmailSubject
$Message.IsBodyHTML = $True
$message.Body = $mbody | ConvertTo-Html -head $style | Out-String
$SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
$SMTP.Send($Message)
}

The script can be edited to change whatever settings you want or send an email that has your company’s logo in it. Each variable that can be changed has comments on the available inputs for that variable. If you would like to encrypt the backup data from unauthorized access you can do that with the $EnableEncryption variable. The easiest way to do that is to create a secure string beforehand that will be saved for this script’s usage.

$SecurePassword = Read-Host -Prompt “Enter password” -AsSecureString

$SecurePassword | ConvertFrom-SecureString > “Directory where secure string should be stored; C:\SecureString.txt, for instance”

This allows you to simply put the path to the .txt file for the script. If you test the script the job should start and upon completion you will receive an email with the details. Then all that is left is scheduling it.

 

Setting a Schedule

Now that we have a simple PowerShell script we can just use Windows Task Scheduler to automate the periodic backups. Just go to Task Scheduler and Action > Create Basic Task….

 

Screen Shot 2016-04-07 at 3.00.05 PM


Set the name and description for it so that you can tell which task runs which script easily. Then hit Next and we’ll set the trigger. How often you backup is determined on your RPO so if you want to run this several times a day or just daily that is up to you. If your RPO is less than a day you may want to think about your recovery plan and if the free edition is really for you.

 

Screen Shot 2016-04-07 at 3.04.11 PM


Simply set the start time you would like the job to run.

 

Screen Shot 2016-04-07 at 3.05.24 PM


Then choose Start a program

 

Screen Shot 2016-04-07 at 3.06.30 PM


In the Program/script field you want to place the following command:

Powershell -file “C:\VeeamBackup.ps1”

Replacing that path with the path to your PowerShell file. Then put a check in the Open the Properties dialog… as we need to make a few changes.

 

Screen Shot 2016-04-07 at 3.09.39 PM


Change the radio of Run only when user is logged on to Run whether user is logged on or not.

 

Screen Shot 2016-04-07 at 3.11.49 PM


Then you can right-click the job and select Run to test the task.

 

 

Screen Shot 2016-04-07 at 3.13.26 PM


Once the backup is completed you should receive your email based on your notification settings. Now that you can do scheduled backups with the Veeam Backup Free Edition you can be sure that your backups are being completed for your virtual environment.