0 0

Scheduling SyncVM Data Refreshes with Tintri Automation Toolkit

Adam talked about how Tintri's SyncVM feature lets you refresh the data of development VMs from a master VM in a virtualized environment. With the 2.0 release of the Tintri Automation Toolkit for PowerShell, you can write PowerShell scripts to do the same, and even better, schedule it to run automatically! Let's look at our example PowerShell function called Refresh-Disks. When invoked, it resolves the VMs and refreshes all the disks of the destination VMs, except the first disk, with the latest snapshot of the source VM.

function Refresh-Disks
{
   <#
   .EXAMPLE
   Refresh-Disks "vmstore01" "master_vm_1" "child_vm_*"

   .DESCRIPTION
   #>

param(
   [string] $tintriServer,
   [string] $sourceVmName,
   [string] $destinationVmNamePattern,
   ...
)

   ....
   ....
   (boilerplate code to connect to the Tintri server and fetch the master VM,
   and the destination VMs to be refreshed) 
    
   # Script to refresh the destination VM disks with the latest snapshot of the source VM.
   # All disks except the first (which is typically the OS disk) will be refreshed.

   Sync-TintriVDisk -VM $destinationVms -SourceSnapshot $snapshot -AllButFirstVDisk
   
   ...
   # More boilerplate code
}

The function takes in a source VM name, a name pattern that captures the destination VMs (assuming they are named so) and the Tintri VMstore to connect to.

Now, how do we schedule this operation so it can be run, say, daily at 3 AM? Enter PowerShell's built in cmdlet  Register-ScheduledJob. We create a trigger for the job using PowerShell's New-JobTrigger cmdlet and register the above script to run when the trigger is fired. Here's how:

$trigger = New-JobTrigger -Daily -At "3:00 AM"

Register-ScheduledJob -Name Refresh-Disks `
    -ScriptBlock { Refresh-Disks "vmstore01" "MyMasterVM" "MyDevVM_*" $credentials } `
    -Trigger $trigger

That's it! When the script is run, all the data disks of VMs whose names start with MyDevVM_ are refreshed with the latest snapshot of the VM MyMasterVM every morning at 3 AM.

You can find the complete code for this example at Tintri's GitHub page.

Cheers!

Dhruv Vemula / Aug 04, 2015

Dhruv Vemula is a Member of Technical Staff at Tintri working on the Automation Toolkit. Prior to Tintri, Dhruv was a software engineer at Cisco working on Cisco's UCS and Nexus 1000V products. Dhr...more

Temporary_css