Managing Virtual Machine Snapshots with vmware-cmd
A snapshot captures the entire state of the virtual machine at the time you take the snapshot.
Virtual machine state includes the following aspects of the virtual machine.
Memory state. Contents of the virtual machine’s memory.
Settings state. Virtual machine settings.
Disk state. State of all the virtual machine’s virtual disks.
When you revert to a snapshot, you return these items to the state they were in at the time that you took the snapshot. If you want the virtual machine to be running or to be shut down when you start it, make sure that it is in that state when you take the snapshot.
You can use snapshots as restoration points when you install update packages, or during a branching process, such as installing different versions of a program. Taking snapshots ensures that each installation begins from an identical baseline. The vSphere Virtual Machine Administration documentation discusses snapshots in detail.
Important Use the vSphere Web Client to revert to a named snapshot. vmware-cmd only supports reverting to the current snapshot.
Taking Virtual Machine Snapshots
You can take a snapshot while a virtual machine is running, shut down, or suspended. If you are in the process of suspending a virtual machine, wait until the suspend operation has finished before taking a snapshot.
If a virtual machine has multiple disks in different disk modes, you must shut down the virtual machine before taking a snapshot. For example, if you have a special-purpose configuration that requires you to use an independent disk, you must shut down the virtual machine before taking a snapshot.
To take a snapshot
1
vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host> /vmfs/volumes/Storage2/testvm/testvm.vmx stop soft
2
vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host> /vmfs/volumes/Storage2/testvm/testvm.vmx getstate
3
Run vmware-cmd with the createsnapshot option.
You must specify the description, quiesce flag (0 or 1) and memory flag (0 or 1).
vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host>
/vmfs/volumes/Storage2/testvm/testvm.vmx createsnapshot VM1Aug09
‘test snapshot August 09’ 0 0
4
The call returns 1 if the virtual machine has a snapshot and returns 0 otherwise.
vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host> /vmfs/volumes/Storage2/testvm/testvm.vmx hassnapshot
 
hassnapshot () = 1
Reverting and Removing Snapshots
You can use vmware-cmd to revert to the current snapshot or to remove a snapshot.
Important You cannot use vmware-cmd to revert to a named snapshot. Use the vSphere Web Client to revert to a named snapshot.
Run vmware-cmd with the revertsnapshot option to revert to the current snapshot. If no snapshot exists, the command does nothing and leaves the virtual machine state unchanged.
vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host> /vmfs/volumes/Storage2/testvm/testvm.vmx revertsnapshot
Run vmware-cmd with the removesnapshots option to remove all snapshots associated with a virtual machine. If no snapshot exists, the command does nothing.
vmware-cmd -H <vc_system> -U <user> -P <password> --vihost <esx_host> /vmfs/volumes/Storage2/testvm/testvm.vmx removesnapshots