Automating backup protection of Virtual Machines using Powershell

Last week we explained how to get started with the Unitrends Powershell Toolkit and how to query any information from Unitrends APIs using Get-UebApi cmdlet.

Today I am going to explain how you can search virtual machines in UEB/RS inventory and how you can automate the operation of adding or removing them from your backup jobs.

Adding virtual machines to a backup job is a great use case for automation as virtual enviroments are very dynamic and new VMs are created and deleted every day. If you are using an orchestrator or portal to automate deployment you can also add a step in your workflow to include the new deployed virtual machines in a backup job using the steps i am going to explain here.

Understanding UEB/RS Inventory

The first thing you need to backup a VM using Unitrends Appliance is to add the virtual host (vCenter, hyper-v, etc) to the list of protected assets.

When you add a virtual host the appliance will sync and retrieve all the virtual machines that are available in the virtual infraestructure at that point-in-time and will cache them into the UEB/RS inventory.

You can query this inventory using:

Get-UebApi -uri "api/inventory"

But we already provide a new cmdlet you can use to explore or search for a VM in the UEB/RS inventory:

Get-UebInventory -Name server01
Get-UebInventory -Name server*

One thing you probably notice is that you can only backup VMs that are cached in UEB/RS inventory, so if you just created a new VM in your infraestructure you will not be able to include it into a backup job until you force a sync inventory operation.

Now you can also do this from command line using:

PS> Sync-UebInventory

And you can monitor sync progress using:

Get-UebApi "api/inventory/sync"

Adding Virtual Machines to a Backup Job

Currently we dont provide an specific API to add or remove a VM from a Job.

To create this Add-UebJobVm cmdlet we had to retrieve the full job configuration and edit the job content to add or remove virtual machine from the instances property and then update the full job specification.

To use this API you need the VM name from inventory and a Backup Job where you want to add the VM, you can get a list of your existing Backups Jobs using:

PS> Get-UebJob

name                     type   last_status status
----                     ----   ----------- ------
Domain_Controller 	 backup Success     Idle
SQL_Server               backup Success     Idle
Oracle                   backup Success     Idle

Now search the inventory for the virtual machine:

PS> Get-UebInventory -Name oracle.server01

And add it to to the job:

PS> Get-UebInventory -Name oracle.server01 | Add-UebJobVm -Job Oracle

You can also add multiple virtual machines to a job using:

PS> Get-UebInventory -Name oracle* | Add-UebJobVm -job Oracle

Removing Virtual Machines from a Backup Job

The process is the same as explained for the add operation but using Remove-UebJobVm.

To remove the VM we just added to Oracle job you can use:

PS> Get-UebInventory -Name oracle.server01 | Remove-UebJobVm -job Oracle

To use all these new cmdlets you will need to download lastest Unitrends Powershell Toolkit from here.

I hope you find this information useful in your day-to-day operations and let’s us know what other powershell cmdlets would be useful for you.


Discover how Unitrends can help protect your organization's sensitive data