x13931x
Contributor
Contributor

Help with ESXi 4: vim-cmd snapshot revert

So, basically I need to automate reverting VMs on my ESXi 4 box to snapshots. With 3.5 I had been using the VIPERL toolkit, but with the licensing lock-down in 4, that's no longer an option. Unfortunately, purchasing a vSphere license is not an option at this time, and neither is reverting to 3.5, so after a bit of research, I discovered the 'vim-cmd' command. I currently have my automation tools SSHing into the ESXi host and calling that command, but I'm running into trouble reverting to snapshots.

The only information I can find on the 'vim-cmd vmsvc/snapshot.revert' command is the help output:

"Usage: snapshot.revert vmid suppressPowerOff "

What I'm trying (and epicly failing) to figure out, is what on earth 'snapshotLevel' and 'snapshotIndex' are supposed to be. I cannot find anything in the snapshot or config files, or in the detailed information on the snapshots or the VM, and I cannot find any information anywhere online that might reference what these parameters might be referencing.

What am I missing here? This seems to be an incredibly powerful tool, but there is so little information available on it anywhere.

0 Kudos
6 Replies
lamw
Community Manager
Community Manager

You are correct, vimsh is quite powerful but also not documented well. You can find some information at our site regarding vimsh at:

I've not extensively used the snapshot functionality with more than 1 level deep snapshot but generally the value will start from 0 and increment, I forge if it was 0 to 1 top to bottom or vice-a-versa.

Say you have a VM named Quentin and it's currently in a powered off state and you would like to capture the state that it's currently in, which is off. You would do something of the following:

[root@himalaya ~]# vmware-vim-cmd vmsvc/snapshot.create 256 powered_off_snapshot powered_off_state 0 0
Create Snapshot:

Note: You'll need to locate the corresponding VmId by doing "vmware-vim-cmd vmsvc/getallvms" if you're not aware of that already

Now, you would power on your VM and do some work/etc. and then at some point later you would like to revert the VM back to the snapshot, you would do something of the following:

[root@himalaya ~]# vmware-vim-cmd vmsvc/snapshot.revert 256 0 0 0
Remove Snapshot:
|-ROOT
--Snapshot Name        : powered_off_snapshot
--Snapshot Desciption  : powered_off_state
--Snapshot Created On  : 9/8/2009 14:8:40
--Snapshot State       : powered off

Note: The syntax to reverting a snapshot is: Usage: snapshot.revert vmid suppressPowerOff \[snapshotLevel\] \[snapshotInde\] and the snapshotLevel and Index really just refers to the dept of the snapshot tree and if there are any branches. You can easily figure this out by doing some testing and leave one of the value to 0 and change the other value to see if it's going to the right snapshot. In our simple example, we will surpressPowerOff and use level 0 and index 0 to revert back to our single snapshot which will bein a powered off state

Hopefully this gives you an idea of how the command works and I would just say run a few tests and you should be able to figure out what those values map to within your snapshot tree but if you have a single snapshot, then it should be pretty trivial to revert.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

Twitter: @lamw

If you find this information useful, please award points for "correct" or "helpful".

x13931x
Contributor
Contributor

I actually have been heavily using that site, thanks, it's a great resource.

Unfortunately, I have not been able to get it to work correctly in testing. Revert functionality seems to be limited to one branch of the tree. In this test VM, the output of snapshot.get is:

Get Snapshot:

|-ROOT

--Snapshot Name : zero

--Snapshot Desciption :

--Snapshot Created On : 9/8/2009 15:58:27

--Snapshot State : powered off

--|-CHILD

-


Snapshot Name : zero_one

-


Snapshot Desciption :

-


Snapshot Created On : 9/8/2009 15:58:49

-


Snapshot State : powered off

-


|-CHILD

-


Snapshot Name : zero_two

-


Snapshot Desciption :

-


Snapshot Created On : 9/8/2009 15:59:0

-


Snapshot State : powered off

--|-CHILD

-


Snapshot Name : one_zero

-


Snapshot Desciption :

-


Snapshot Created On : 9/8/2009 15:59:37

-


Snapshot State : powered off

I can revert to any of the snapshots in the first branch just fine, but when I try to go to the second branch, it fails.

snapshot.revert 0 0 0 =loads=> zero

snapshot.revert 0 1 0 =loads=> zero_one

snapshot.revert 0 2 0 =loads=> zero_two

Any other combination (0 0 1, 0 1 1) fails with no error message. They didn't restrict the free license to accessing one branch did they?

0 Kudos
lamw
Community Manager
Community Manager

I actually just got it working .... the issue lies with having that single 'ROOT' snapshot. If you remove that, then you can effectively get to any of the branches where snapshotLevel defines the individual branches which start from 0 and up, this would be your snap_0_0 and snap_1_0 and snap_2_0. The snapshotIndex would be the child snapshots such as 0_1,0_2,1_1,1_2,etc.

Here is an example:

[root@himalaya ~]# vmware-vim-cmd vmsvc/snapshot.get 256
Get Snapshot:
|-ROOT
--Snapshot Name        : snap_0_0
--Snapshot Desciption  :
--Snapshot Created On  : 9/8/2009 14:50:52
--Snapshot State       : powered off
--|-CHILD
----Snapshot Name        : snap_0_1
----Snapshot Desciption  :
----Snapshot Created On  : 9/8/2009 14:51:17
----Snapshot State       : powered off
|-ROOT
--Snapshot Name        : snap_1_0
--Snapshot Desciption  :
--Snapshot Created On  : 9/8/2009 14:52:1
--Snapshot State       : powered off
--|-CHILD
----Snapshot Name        : snap_1_1
----Snapshot Desciption  :
----Snapshot Created On  : 9/8/2009 14:52:21
----Snapshot State       : powered off
|-ROOT
--Snapshot Name        : snap_2_0
--Snapshot Desciption  :
--Snapshot Created On  : 9/8/2009 15:8:2
--Snapshot State       : powered off

I think what happens is when you first create a snapshot, a single root is referenced. So all snapshots under that root are considered children and from what I can see from my testing, you can't acess the other child tree as you've mentioned already. If you go back and just delete the main root, then each of the main children become their own 'ROOT' node and then the subsequent snapshot under each root are the children snapshot. In this case you can access the 3 root's by doing (0,1), (0,2) and (0,3) respectively based on my sample.

This has just been some simple testing, in terms of why ... I'm still not sure

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

Twitter: @lamw

If you find this information useful, please award points for "correct" or "helpful".

x13931x
Contributor
Contributor

Thanks, that fixed some of my problems; now I can address multiple branches, but not sub-branches, which makes sense, considering there are only two reference numbers..annoying, but it makes sense.

Does anyone know if there is some way that I can revert to a snapshot using either its name or id (obtained from vmsvc/get.snapshotinfo) in the free licensed version of 4.0? It feels like there should be; after all, the perl scripts and VIX APIboth call the name, and looking at the log files, when I do it from the VI client, whatever function that actually calls on the server calls it by name.

Grrr, frustrating...why does VMWare keep cutting features from the free version? It's like they were trying to make money off it or something 😛

0 Kudos
lina706
Contributor
Contributor

I have some problem on this issue too.

I have the followed hierarchy snapshot:

|-ROOT
--Snapshot Name        : Ready
--Snapshot Desciption  :
--Snapshot Created On  : 11/20/2011 18:21:31
--Snapshot State       : powered off
--|-CHILD
----Snapshot Name        : Ready
----Snapshot Desciption  :
----Snapshot Created On  : 12/13/2011 17:5:53
----Snapshot State       : powered off
--|-CHILD
----Snapshot Name        : Test
----Snapshot Desciption  :
----Snapshot Created On  : 12/13/2011 18:45:19
----Snapshot State       : powered off
----|-CHILD
------Snapshot Name        : Test01
------Snapshot Desciption  :
------Snapshot Created On  : 12/13/2011 18:45:32
------Snapshot State       : powered off
I want to revert to Test level through : vim-cmd vmsvc/snapshot.revert 2 0.but I always fail.  Actually I could not well catch the mean of  [snapshotLevel] and [snapshotIndex]. Could someone explain these parameters?
0 Kudos
PhilippH
Contributor
Contributor

I'm also interested in how to create multiple root snapshots.

I tried a lot, but I was not able to create multiple root snapshots..

Only multiple parallel children below the first child snapshot..

0 Kudos