There have been multiple posts in the community about the size of the snapshots and how it should be calculated. There are some issues with the “SizeMB” property of the Snapshot object, so this post will try to explain what these problems are and what is the correct way to calculate snapshot sizes.
We’ll try to keep things simple and not go in too much detail. To start off let’s imagine you have a virtual machine with a single hard disk. This disk is represented as a “vmdk” file in the datastore (e.g. VM.vmdk). Whenever you write something on the hard disk of the VM it is saved in that VM.vmdk file (figure-1).
When you create a snapshot this VM.vmdk file gets “frozen” and a new one (VM-1.vmdk) is created. The “frozen” VM.vmdk file represents the exact state of the VM’s hard disk at the time when the snapshot was taken. From that point on all changes on the VM’s hard disk are reflected in the new VM-1.vmdk file. Also a new “vmsn” file is created (e.g. Snapshot1.vmsm) which represents the state of the VM’s memory at the time of the snapshot creation (figure-2).
Similarly when a second snapshot is taken VM-1.vmdk gets “frozen” and VM-2.vmdk and Snapshot2.vmsn files are created, the same thing happens when we create a third snapshot (figure-3).
So how is the snapshot size calculated?
For each snapshot the size includes the sizes of the files needed to capture the state of the VM at snapshot time (e.g. hard disk and memory).
For Snapshot2 (figure-3) these files are Snapshot2.vmsn and VM-1.vmdk. The VM-1.vmdk contains all changes made after the first snapshot and it is required part of Snapshot 2.
For the currently active snapshot (e.g. Snapshot3), its size also includes the file which stores disk changes after the snapshot (e.g VM-3.vmdk, figure-3). Thus Snapshot3 files are Snapshot3.vmsn, VM-2.vmdk and VM-3.vmdk. VM-2.vmdk contains all changes since previous snapshot and VM-3.vmdk contains the current changes.
The root snapshot (e.g. Snapshot1) is based directly on the VM’s disk (e.g. VM.vmdk) but its size is not calculated (it’s calculated towards the size of the hard disk itself, not the snapshot). That way the files calculated in the size of each snapshot are the ones marked in orange in figures 2 and 3.
(Note: if we consider figure 3 and imagine that Snapshot2 is the currently active snapshot, then the size of VM-3.vmdk will be calculated in Snapshot2’s size, not Snapshot3’s)
Now for the “SizeMB” property of the Snapshot object. When calculating its value we use the above mentioned approach and calculate the size correctly for ESX 3.0 and 3.5. However there are some changes in the API behavior from 3.5 to 4.0 that we overlooked, thus resulting in wrong calculation of the snapshot size on ESX 4.0.
This issue will be fixed in a future release, but until then you can use the attached script to get the correct snapshot sizes. The script works on all ESX versions and uses the above mentioned approach for calculation.
Download GetSnapshotSize.ps1(fixed)
Dimitar Hristov & Vitali Baruh
PowerCLI Team