First things first: this is not a sponsored article.
I came across Veeam products multiple times in my career, but most of the customers or companies that I worked for were using other products with no compelling reason for migrating from backup solutions that already worked efficiently with another one.
In the last couple of years, I’ve attended to VMWare UserCon and met some guys from Veeam, that was one of the sponsors of the event in here Melbourne (Australia). They were very approachable and kind to show that the company had a lot of new solutions to offer and one, in particular, it was too good to be true.
The solution was called VeeamZIP and now is part of a product called Veeam Backup and Replication. It’s free, it’s supported by the company (I think just via the forum or email) which I think is a very important point and not just support VM WARE (vSphere) and MS Hyper-V, but have a neat graphical console and a cli… that it’s Powershell! Working with VMWare or HyperV means already being capable of using Powershell, but using it also for the backup (or other features) it’s a big bonus. I can’t find any drawback on this product, really.
As DevOps /System Engineer I also work a lot on lower (dev/test) environments that sometimes have a very short life, not entirely managed by a configuration manager. So these environments are made of a lot of moving parts that are not stateless or immutable, so I can’t simply “destroy” them and rebuild them entirely from scratch without spending a considerable amount of time.
In this scenario is being flexible and fast means at the same time an efficient use of time and money. The best solution, in this case, is not necessarily free but the one that perfectly meets and matches the requirements.
The Requirements
The requirements in my case were meeting the needs of Developers and Operations to archive/freeze sometimes multiple VMs on demand as described before.
These are not basically checkpoints or daily backups, but more an ad-hoc process for temporary projects or proof of concepts. So I wanted to exclude them from the production backups part of the business continuity/disaster recovery plan.
This data/system is important enough to be backed up, but it’s not critical for the business. Especially in my case over time the number of these VMs it’s in the order of hundreds and growing over time and if not managed properly it’s noise or simply too expensive to maintain.
The compression rate for my standard size Windows VM with a couple of virtual disks was impressive, especially the speed for backup or restore was less than 5 minutes for each VM or a quick coffee break.
As a DevOps the neat UI to access and configure the tool is a bonus, but not exactly what I was looking for. The CLI (powershell) offers the opportunity to tailor it to my needs.
For Example
If we tag VMs with a label like “PoC-001” (in Veeam B&R) and create a RBAC permission via the UI for developers we can provide from the UI the permission to backup or restore. But from the console/script that can be signed and ran on demand, we can trigger other events like an email to a distribution list or notify to a chatbot/chatops when the event is completed, add/remove rules to firewall or entry monitoring systems, using rest api creating service desk tickets for these events for raising visibility and merging the flow of the project or company, etc… and everything else you need or possibly think of.
This is a good starting point with Veeam PS Snapin:
https://helpcenter.veeam.com/docs/backup/powershell/getting_started.html?ver=95
Installing the Veeam Backup & Replication was a streamlined experience. The configuration as well, in my case, considering that the infrastructure and tool from VMWare and MS Hyper-V SCVMM were already there. I’ve used the UI to store the credentials, creating the users’ profiles (RBAC) and test the overall functionality.. then I started to work on the CLI.
So let’s start by exploring the free options in this article (VeeamZIP) included on Veeam Backup and Replication (the version I’ve tested and used is 9.5).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#requires -runasadministrator #Paolo Frigo, https://www.scriptinglibrary.com #add the veeam snapin Add-PSSnapin VeeamPSSnapIn #check all the availabe cmdlets Get-Command -module veeampssnapin #connect to a veeam backup server Connect-VBRServer #get the details user, server, port of the opened connections Get-VBRServerSession |
Ok, now that we are connected to the Veeam Backup server within our powershell session let’s connect to vSphere or HyperV and gather some of the settings.
1 2 3 4 5 6 7 8 9 10 11 |
#get a list of all Servers MS HYPER-V and or VMWare-vSphere Get-VBRServer #Find the VM on WMWARE Find-VBRViEntity #Find the VM on Hyper-V Find-VBRHvEntity #Get the VBR Credentials Get-VBRCredentials |
Let’s define in our script the environment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#Let's use this example #Let's define an hyper v node and a single vm as a target $hyperv_node = "hyper-lab.contoso.com" # or a list of nodes $vm_name = "test-web01" $vm=Find-VBRHvEntity -server $hyperv_node -name $vm_name $nas="\\nas.contoso.com\Archive" $vmm_cred = Get-VBRCredentials | Where-Object {$_.description -like "scvmm"} #EMAIL SETTINGS $mailserver = "mail.contoso.com" $smtpport=587 $emailsubject = "VM Full backup - VEEAMZIP Weekly report" |
Let’s check if the VM and the node are there:
1 2 3 4 5 |
#let's find our VM Find-VBRHvEntity -server $hyperv_node -name $vm_name #Or list the all the VMs Get-VBRServer -Name $hyperv_node | Find-VBRHvEntity |
Let’s start the asynchronous backup job and in the meantime let’s send out an email with all the files and size occupied on disk on our backup repository/archive.
1 2 3 4 5 6 7 8 9 10 11 |
#Compress with VeeamZip Start-VBRZip -Folder $nas -Entity $vm -Compression 4 -DisableQuiesce -AutoDelete Never -NetworkCredentials $vmm_cred -RunAsync #Send an email Send-MailMessage -subject "VeeamZIP Backup: $vm_name " -Body "Backup Started at $(Get-Date)" -From $email_notify_from -to $email_notify_to -SmtpServer $mailserver -port $smtpport #These is a weekly report $BACKUP_SUMMARY = Get-ChildItem $nas | SELECT NAME, LastWriteTime, @{N='SizeInGB';E={[math]::Round($_.length / 1GB,2)}} | WHERE {$_.LASTWRITETIME -gt $(Get-Date).ADDdAYS(-7) } | ConvertTo-Html #Send a report on the archive content Send-MailMessage -subject $emailsubject -BodyAsHtml "$BACKUP_SUMMARY" -From $email_notify_from -to $email_notify_to -SmtpServer $mailserver -port $smtpport |
I hope you find this article interesting, as usual, you can find these code snippets on my GitHub repository.
After writing this article I’ve found a good one on an older version of VeeamZip that performs similar operations: https://www.veeam.com/blog/veeam-backup-free-edition-now-with-powershell.html
Hello Paolo
Thank you for sharing this script. I noticed, the mail is sent before the job is finished. Is there a possibility to send the mail after the Backup has finished and perhaps add the status of the finished backup?
Thank you
Hi Stefan,
Good point and thanks for your comment. If you want to receive the email once the backup it’s completed remove
[-async]
(which it’s an optional parameter) fromStart-VBRZip
.As you can read from
get-help Start-VBRZip -detailed
-RunAsync []
Indicates that the command returns immediately without waiting for the task to complete.
I hope it’s what you were looking for.
Thanks.
Hi Paolo
Thank you. That’s what I was looking for.
Thanks