Technical

How to Create Unitrends Event Driven Backups through Scripting

Have you ever wondered how you could create event driven backups through scripting? Back in November, we blogged about one of the many ways Unitrends provides radical ease of use, with the introduction of our new REST APIs. (Part 2 – RESTful API)  As mentioned in that blog post, the Unitrends Backup 9.0 release is built upon a

5 minute read

Have you ever wondered how you could create event driven backups through scripting?

Back in November, we blogged about one of the many ways Unitrends provides radical ease of use, with the introduction of our new REST APIs. (Part 2 – RESTful API)  As mentioned in that blog post, the Unitrends Backup 9.0 release is built upon a set of RESTful APIs that can be accessed from a Command Line Interface and from any number of popular scripting languages.  In this blog post, we will cover event driven backup scripts and provide a couple of real world examples of how we assisted a customer meet their business requirements using a few simple scripts.

If you’re like me and took some scripting or programming classes at some point, you understand that scripting is an intriguing way to solve issues and business objectives, while minimizing administrative effort. In many cases, it allows for more detailed management beyond what’s available in the standard user interface.  In this particular case, I was assisting a Unitrends customer with these three tasks:

  • Start a job on demand
  • Enable a job
  • Disable a job

Although each task above is easily completed in the web UI, the times and frequencies these tasks needed to be run were not friendly to a reoccurring schedule, therefore, event driven scripts were the answer.   The ability to enable or disable a job through a script was requested because the customer had independent archive scopes for monthly and weekly archives.  This created a timing issue when both the monthly and weekly archive jobs were scheduled to run on the same weekend.  By leveraging a script, the customer could create their own schedules and tasks that would automatically disable a weekly archive job when the monthly archive job was going to run.

In similar fashion, not all backup jobs can be scheduled to reoccur at the same time each day if a dependent process is inconsistent. In this case, the customer was looking for Unitrends to backup an Oracle RMAN backup file.  Without a consistent start and end time for the RMAN job, it’s difficult to schedule a backup with 100% certainty it will grab the completed backup file, and only after the Oracle processes have completed.   However, by leveraging a script to start the job on demand, we can link the two processes together.  This way, as soon as the Oracle RMAN backup is complete, the Unitrends backup can be started and the customer will have the least amount of exposed risk, along with the shortest possible RPO.

To complete these tasks, the customer requested local scripts to run from Linux servers to execute a local Unitrends command. This is a little unique, while a more common scenario would be a PowerShell script run from a Windows system.  I’ll provide both examples below, along with CLI commands leveraged by the customer.

 

Local commands run from the Unitrends CLI

In order to manipulate jobs from the CLI, you need to know the job ID you want to target and you must first authenticate (via SSH) to the appliance.   When looking for additional options and commands for use with the Unitrends CLI, you can reference the help menu by using the –h command option.

 

Once authenticated, you can get the job ID by reviewing current backup jobs with this command:

unitrends-cli get joborders -t backup

 

Then find the correct backup job and note the corresponding job ID. Using the command [unitrends-cli put joborders -i <backup ID> –<options>] you can complete the required tasks.

 

To disable a job, assuming job ID 30e, call this command in the script:

unitrends-cli put joborders -i 30e –d

 

To enable a job, assuming job ID 30e, call this command in the script:

unitrends-cli put joborders -i 30e -e

 

To run a job on demand, assuming job ID 30e, call this command in the script:

unitrends-cli put joborders -i 30e –r

 

 

PowerShell for Windows Users

For Windows users that would like to leverage PowerShell and remote scripts, here are similar example scripts you can use to accomplish the same tasks.

 

To disable a job:

Place contents in script file (i.e. DisableUEBJob.ps1) and replace or update items colored purple.


#Load Unitrends modules and ignore output help replace with the path to unitrends.psm1

import-module “C:\Unitrends\unitrends-pstoolkit\unitrends-pstoolkit\Unitrends.psm1” | Out-Null

 

Write-Host “Connecting to UEB”

Connect-UebServer -Server UEB_Hostname -User root -Password Password

 

#Disable all jobs that start with Test* in the name

Write-Host “Disabling Test Jobs”

$jobs = Get-UebJob -Name Test*

 

foreach($job in $jobs) {

$job|Disable-UebJob

}

 

Write-Host “End of my script”

 


To enable a job:

Place contents in script file (i.e. EnableUEBJob.ps1) and replace or update items colored purple.


#Load Unitrends modules and ignore output help replace with the path to unitrends.psm1

import-module “C:\Unitrends\unitrends-pstoolkit\unitrends-pstoolkit\Unitrends.psm1” | Out-Null

 

Write-Host “Connecting to UEB”

Connect-UebServer -Server UEB_Hostname -User root -Password Password

 

#Enable all jobs that start with Test* name

Write-Host “Enabling Test Jobs”

$jobs = Get-UebJob -Name Test*

 

foreach($job in $jobs) {

$job|Enable-UebJob

}

 

Write-Host “End of my script”

 


To launch a job on demand:

Place contents in script file (i.e. LaunchUEBJob.ps1) and replace or update items colored purple.


#Load Unitrends modules and ignore output help replace with the path to unitrends.psm1

import-module “C:\Unitrends\unitrends-pstoolkit\unitrends-pstoolkit\Unitrends.psm1” | Out-Null

 

Write-Host “Connecting to UEB”

Connect-UebServer -Server UEB_Hostname -User root -Password Password

 

#Launching job named Test

Write-Host “Launching Job Test”

Get-UebJob -Name Test |Start-UebJob

 

Write-Host “End of my script”


Like most things, scripting is an art and one that includes many valid ways to achieve success. If you have any suggestions or use cases of your own that you’d like to share, we’d love to hear from you.

See Everything Unitrends Backup Appliances Have to Offer

Appliances range from 2-120TB and are available in high-performance desktop and robust rackmount formfactors. Regardless of the use case, there’s a backup appliance that caters to it.

Request a Demo