VMware Cloud Community
IT_Architect
Enthusiast
Enthusiast
Jump to solution

How do I make and remove a snapshot from the command line in ESXi 4?

How do I make and remove a snapshot from the command line in ESXi 4? ghettoVCB4i does this, but I need some unusual behavior for two VMs. I need to be able to backup only one of the two virtual disks, not both. Thus I cannot use that script here. I need to write a script that will:

1. Copy off the .vmx

2. Make a snapshot of a running VM

3. Use vmkfstools to clone the vmdk to the backup location

4. Remove the snapshot.

The snapshot is the part I don't know how to do. I don't see a snapshot command in vmkfstools and I don't understand the snapshot code in ghettoVCB4i.

Thanks!

0 Kudos
1 Solution

Accepted Solutions
lamw
Community Manager
Community Manager
Jump to solution

vmkfstools is a tool to work with VMDKs, it has nothing to do with snapshots. In the unsupported Busybox console, the only tool you'll be able to use for some of the VM management is vim-cmd which is pretty much a wrapper to VMware vimsh, take a look at our site for more info:

Basically you'll do somethign like the following:

vim-cmd "vmsvc/snapshot.create XXXX FIRST_SNAPSHOT MY_FIRST_SNAPSHOT_1"

where XXXX is the VM's VmId that is retrieved from vmsvc/getallvms and then you'll issue the snapshot.remove

Here are other useful commands dealing with snapshots:

vim-cmd vmsvc/snapshot.removeall \[VmId]

vim-cmd vmsvc/snapshot.remove \[VmId\] \[removeChildren\] \[snapshotLevel\] \[snapshotIndex\]

vim-cmd vmsvc/snapshot.get \[VmId\]

ghettoVCB4i utilizes vimsh to do all this as well.

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

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

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

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

View solution in original post

0 Kudos
2 Replies
lamw
Community Manager
Community Manager
Jump to solution

vmkfstools is a tool to work with VMDKs, it has nothing to do with snapshots. In the unsupported Busybox console, the only tool you'll be able to use for some of the VM management is vim-cmd which is pretty much a wrapper to VMware vimsh, take a look at our site for more info:

Basically you'll do somethign like the following:

vim-cmd "vmsvc/snapshot.create XXXX FIRST_SNAPSHOT MY_FIRST_SNAPSHOT_1"

where XXXX is the VM's VmId that is retrieved from vmsvc/getallvms and then you'll issue the snapshot.remove

Here are other useful commands dealing with snapshots:

vim-cmd vmsvc/snapshot.removeall \[VmId]

vim-cmd vmsvc/snapshot.remove \[VmId\] \[removeChildren\] \[snapshotLevel\] \[snapshotIndex\]

vim-cmd vmsvc/snapshot.get \[VmId\]

ghettoVCB4i utilizes vimsh to do all this as well.

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

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

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

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

0 Kudos
IT_Architect
Enthusiast
Enthusiast
Jump to solution

I started writing a short script to do a backup just the first vmdk of a couple VMs where I needed that behavior. Then I decided to simply make a copy of your script, make a separate vm list, and put a break at the end of the loop where you cycle through the vmdks so it wouldn't backup the remainder.

Thanks!

0 Kudos