VMware

The PowerCLI Universe Continues to Expand - New session added to VMworld | Main | vSphere PowerCLI - Thank you for a great VMworld 2010 - SF !

September 03, 2010

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). 

SnapshotSizeFig1
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).

SnapshotSizeFig2

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).

SnapshotSizeFig3

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


TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c328153ef0133f39296a2970b

Listed below are links to weblogs that reference Snapshot Size:

Comments

LucD

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.

Robbie Wiley

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.

Vitali Baruh

Hello,

The script was written using PowerCLI 4.1. Now it works also with version 4.0u1.

Thanks.

David Chan

Hello,

Do you have a release date for this snapshot size bug ? Is it stil there with ESX 4.1 ?

Thanks

Post a comment

If you have a TypeKey or TypePad account, please Sign In.

About this Blog

This blog provides insight and highlights for VMware PowerCLI, the best tool for automating management and configuration of VMware vSphere.

Subscribe via RSS  

Recommended Reading

Pimp your PowerCLI

Twitter


Facebook

    VMware Blogs