Snapshot Size

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


16 comments have been added so far

  1. Great article.
    I know the definition of a snapshot’s size is like you defined it in the text above, but I still think you need to know what ‘extra’ disk space is needed when you create a snapshot.
    That’s what I tried to do in my http://www.lucd.info/2010/03/23/yadr-a-vdisk-reporter/ post.
    Btw, if you want a nice diagram of your disks and snapshots, you can use my http://www.lucd.info/2010/03/31/uml-diagram-your-vm-vdisks-and-snapshots/ post, where I followed that same logic.

  2. I had to modify the CalculateVMSnapshotsSizeMB function to use $vmView = Get-View $vm.id as the first line. Get-View didn’t like just getting the entire VM as an input.

  3. How to get the Virtual Machine Snapshot Space using vi java api? Is there any method or property to get snapshot space ? ..Plz help me..!!!

  4. Your nature fell on your only purple nature and have to yell to you which you will be smileful. The best writing is the collection that I feels for in their lives. You must make electric writings. Nature.

  5. Your style is very unique in comparison to other people I have read
    stuff from. Thanks for posting when you have the opportunity, Guess I’ll just bookmark this web site.

  6. I was curious if you ever considered changing the page layout of youhr website?

    Its very well written; I love what youve got to
    say. But maybe you coould a little moore in tthe way of content so peoople could connect witth it better.

    Youvee got an awful lot of text for only having 1 or two images.
    Maybe you could space iit out better?

  7. My brother recommended I might like this blog. He was totally
    right. This publish truly made my day. You can not believe simply how so much
    time I had spent for this information! Thank you!

Leave a Reply

Your email address will not be published.