Categories
How-To Software Technical

Quest to automate snapshots in ESXi

I am looking for a way to run a instance and have it revert back to its snapshot every 24 hours. I started toying around with the idea to use the vim-cmd features however there doesn’t seem to be a way to set a task for this.

So far here are the steps I used

Looked up the ID of the VM in question by running:

vim-cmd vmsvc/getallvms

View your VM’s snapshot tree by passing its ID to this command (this example uses the VM with ID 50):

vim-cmd vmsvc/get.snapshotinfo 80

And issues the command to revert the snapshot

vim-cmd vmsvc/snapshot.revert VM_ID 0 SNAPSHOT_ID suppressPowerOff

 

The output looks something like this in my testing

~ # vim-cmd vmsvc/getallvms
Vmid      Name                         File                         Guest OS       Version   Annotation
50     torproxy      [datastore3] torproxy/torproxy.vmx         ubuntu64Guest      vmx-08
56     workstation   [datastore3] workstation/workstation.vmx   windows8_64Guest   vmx-08
61     freepbx       [nfs] freepbx/freepbx.vmx                  centosGuest        vmx-08
66     webserver     [datastore3] webserver/webserver.vmx       ubuntu64Guest      vmx-08
~ # vim-cmd vmsvc/get.snapshotinfo 50
(vim.vm.SnapshotInfo) {
   dynamicType = <unset>,
   currentSnapshot = 'vim.vm.Snapshot:50-snapshot-7',
   rootSnapshotList = (vim.vm.SnapshotTree) [
      (vim.vm.SnapshotTree) {
         dynamicType = <unset>,
         snapshot = 'vim.vm.Snapshot:50-snapshot-7',
         vm = 'vim.VirtualMachine:50',
         name = "working",
         description = "",
         id = 7,
         createTime = "2014-12-16T01:27:35.7054Z",
         state = "poweredOn",
         quiesced = false,
         backupManifest = <unset>,
         replaySupported = false,
      }
   ],
}
~ # vim-cmd vmsvc/snapshot.revert 50 7 suppressPowerOff
Revert Snapshot:
|-ROOT
--Snapshot Name        : working
--Snapshot Id        : 7
--Snapshot Desciption  :
--Snapshot Created On  : 12/16/2014 1:27:35
--Snapshot State       : powered on

This works and now all I need is to somehow automate and schedule this.

2 replies on “Quest to automate snapshots in ESXi”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.