This is a guest post by Vladimir Eremin, a product manager at Veeam. Vladimir is very active on the Veeam Forums, Twitter and in Spiceworks. One of Vladimir’s skills is PowerShell and he walks through this process here in this guest blog post. If you have any question on the PowerShell parts mentioned in this post, use the Veeam Forums to discuss. You an also download the sample script here for VMware and the sample script here for Hyper-V and discuss this topic in the Veeam Forums.
Our Veeam Backup Free Edition has been the most popular free Veeam tool, mostly thanks to its VeeamZIP functionality: ability to perform interactive full backups of unlimited amount of VMs. However, VeeamZIP has always had one small yet irritating limitation – the inability to schedule performing regular backups. Indeed, due to the fact that VeeamZIP can only be triggered interactively, there is simply no means in UI to schedule it like regular backup jobs. If you have been down this path, you will be happy to know that as of Update 2, this is no longer the case! In areas like the Veeam forums, our engagement on Twitter and other areas; we have recognized the concern and decided to address it by making Start-VBRZip PowerShell cmdlet available in Free Edition.
4-April 2016 Note: Update your PowerShell to version 3.0 at least prior to using this script, as we’ve discovered number of odd issues while working with PowerShell 2.0.
How it works
As noted earlier, the main functionality Veeam Backup Free Edition is ability to perform VeeamZIP backups of your VMs (and, of course, to recover VMs, guest files and application items from those backups). VeeamZIP always produces a full backup file (.vbk) that acts as an independent restore point. Free Edition allows you to store the backup file on a backup repository, on a local folder or on a network share.
When you perform backup with VeeamZIP, you can start the backup process for selected VM immediately. This type of backup requires minimal settings, and as such is extremely easy to trigger manually.
With Update 2, you can now write a simple PowerShell script (here for VMware and here for Hyper-V) that starts VeeamZIP activity for a selected VM, and sets whatever schedule you want for it via Windows Scheduler. We have even created the following example script for you that will not only trigger VeeamZIP backups of the required VMs, but will also email you a nicely formatted report with backup results!
The script is able to perform ad-hoc backup of selected VMs residing on both standalone host or cluster, or vCenter server. Before executing script, you need to provide three mandatory parameters: names of VMs to backup, host those VMs are located at, and directory where backup files should be stored. Note, this script was updated on 5/18 due to feedback.
Processing finished with warnings at 3/26/2015 6:07:13 PM Cannot use VMware Tools quiescence because VMware Tools are not found.
3/26/2015 6:07:20 PM
3/26/2015 6:11:20 PM
Processing finished at 3/26/2015 6:11:18 PM
All of the abovementioned settings can be configured by setting certain variables to the corresponding values. For instance, to enable encryption, you should set $True (Boolean) value to $EnableEncryption variable, and provide the encryption key (see the next chapter). Additionally, if you want the backup files to be deleted after two weeks, you should set “In2Weeks” (string) value to $Retention variable, etc. There is no need to remember what each and every variable does and what values are acceptable – for your convenience, the example script include a short description for each variable.
Getting back to encryption, data security is a critical part of the backup strategy. Backup data must be protected from unauthorized access, especially when a sensitive VM data is backed up to an offsite location or archived to tapes. To keep your data safe, you can encrypt your VeeamZIP backups. As noted above, this requires choosing a file containing the encryption password.
Of course, you could provide the password to a script as a plain text string. However, regular strings are insecure (to the say the least), since they are stored in memory as plain text. As a result, most PowerShell cmdlets will simply not accept passwords in this form.
A secure string is a better option. This type is like the usual string, but its content is encrypted in memory. It uses reversible encryption so the password can be decrypted when needed, but only by the principal that encrypted it. To create a secure string you need to open the PS console, and type the following two lines. When executed, the code will ask you to prompt a password and, then, save it as a secure string into a file:
$SecurePassword | ConvertFrom-SecureString > “Directory where secure string should be stored; C:\SecureString.txt, for instance”
After that, specify the path to the newly-created file in the main script:
# Protect resulting backup with encryption key (Optional; $True/$False)
$EnableEncryption = $True
# Encryption Key (Optional; path to a secure string)
$EncryptionKey = "C:\SecureString.txt"
Scheduling the script
Before you schedule the script, be sure to try starting it manually to ensure that it performs as expected.
The easiest way to schedule the script to perform periodic backup automatically is to use Windows Task Scheduler. Simply go to the Task Scheduler tool, and create a new basic task:
Assign a name and a description for it, so that you can easily remember what this task does.
The next page is the Task Trigger. It is pretty basic, and self-explanatory. The available options are quite flexible (everything from running backups several times a day or once a month is possible), so set there whatever values that address your RPO requirements. Most people use daily backups:
Set the start time for the task for the off hours. In this example, the task runs every evening at 22:00 PM beginning on April 22, 2015.
On the subsequent Action page, specify that you want the scheduled task to Start a program, and then click Next.
On the Start a Program pane, you place the following command into Program/script:
Powershell –file “Path to Veeamzip.ps1 file”
That’s it! But we may want to open the task once it is created to make a couple of additional changes. To do so, select the Open the Properties dialog for this task when I click Finish:
Since the task is to be run on a server, where a user might not be logged when the task takes place, it is worth to enable the task to run regardless of whether or not the user is logged on by associating the user’s credentials with the task.
Once you’re done, right-click the job and select Run to ensure that the task completes properly:
PowerShell gives the users what they have always wanted from Veeam Backup Free Edition!
Now that you are armed with this new awesome capability, you now should be able to achieve the long-awaited goal – do scheduled backups with the use of Veeam Backup Free Edition, which provides far more backup and recovery features than script-based free backup solution alternatives.
Veeam Backup Free Edition: Now with PowerShell!, 4.7 out of 5 based on 22 ratings
Author: Rick Vanover
Rick Vanover (MVP, vExpert, Cisco Champion) is the director of Technical Product Marketing & Evangelism for Veeam Software based in Columbus, Ohio. Rick’s IT experience includes system administration and IT management; with virtualization being the central theme of his career recently. Follow Rick on Twitter... More