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 can 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 the 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!

Script parameters

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.

##################################################################

# User Defined Variables

##################################################################

# Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”

$VMNames = ""

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)

$HostName = ""

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)

$Directory = ""

Optionally, you can change compression level and desired retention, disable VMware quiescence, enable encryption or even notification settings:

# 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 or Hyper-V Integration Components are required for this in the guest OS; 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"

If you like to get an email report once the backup is completed, you should additionally fill out the following notification settings.

##################################################################

# Notification Settings

##################################################################

# Enable notification (Optional)

$EnableNotification = $True

# Email SMTP server

$SMTPServer = ""

# Email FROM

$EmailFrom = ""

# Email TO

$EmailTo = ""

# Email subject

$EmailSubject = ""

The resulting email report will look like this:

Name Start Time End Time Result Details CentOS-tiny_2015-03-26T180459 3/26/2015 6:04:59 PM 3/26/2015 6:07:17 PM Warning Processing finished with warnings at 3/26/2015 6:07:13 PM Cannot use VMware Tools quiescence because VMware Tools are not found. CentOS-tiny_replica_2015-03-26T180720 3/26/2015 6:07:20 PM 3/26/2015 6:11:20 PM Success 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.

Encryption

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 = Read-Host -Prompt "Enter password" -AsSecureString

$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.

Check out these other cool resources:

GD Star Rating

loading...