Watch out for snapshots… l invisible snapshots ;)


I guess everybody had that :/
Sometimes when you keep snapshots for too much time you will end up with 0 mb free space on datastore. Believe me, you do not want this to happen. You can defend yourself from this in several ways, creating reporting scripts, alerts, active monitoring etc…
The easiest and i guess the fastest way is to use information from this KB. It will take you only 1-2 minutes to complete it, so it is really worth to spend this time on setting this up.
I am still thinking if this alert will trigger when you will have ‘corrupted’ information about the snapshots within vm. Maybe i am using bad word here but, i will try to describe possible situation.
Let’s say that for some reason you check the snapshot manager on some VM and you see that there is no snapshot. When you check settings of this vm, you can see that hard drive is running from file -00001 for example. That would indicate that in fact it is running from a delta file. It is also possible that your vm is running using multiple snapshots. Again for some reason you do not have to see this information within vSphere client in snapshot manager.
I will try to explain how to check those snapshots even if you do not see them in vSphere client, but first what to do in case if you have a snapshot(you have identified that vm is running using delta disk) but you can not see it within gui.
Open snapshot manager, create new snapshot. After this is done and new snapshot was created without problem, delete the snapshots using [delete all] button from snapshot manager. You will see that this will delete ALL snapshots, not only the one that you have created few seconds ago, but all those that you can see in vm directory(for example you can see delta files -000001/2/3/4/5…) but are not reported in snapshot manager.
Ok, if everything went fine your vm should not have any snapshots by now.
Safety first…
It is also worth to double check the if all snapshots have proper values for CID/ParentCID.
Each disk descriptor file ‘*-000001.vmdk’ should have information about his contentID, and also information about who is his parent.
Sometimes when a snapshot is very old it is worth checking if the parentCID is still there. So you have to read contents of the descriptor file and check the value of ParentCID, note it down, then open next file which will be mentioned as parentFileNameHint , and check if his CID is the same as the ParentCID mentioned in that previous snapshot vmdk. If you would have 2 snapshots you would see files for example:

vmname.vmdk
vmname-000001.vmdk
vmname-000002.vmdk

So you would have to start from reading vmname-000002.vmdk, parentCID should be the same as CID value in file vmname-000001.vmdk.
Then, read the ParentCID from file vmname-000001.vmdk, it should be the same as the CID in vmname.vmdk. And finally, the parentCID in vmname.vmdk should be equal to “parentCID=ffffffff”. That would mean that the snapshots chain is completed.
Ok, back to those snpashots that we can not see using snapshot manager within vSphere client.
I wrote this one liner to get all vms that have vmdk disks attached with name *-000000.vmdk Where 000000 could be any number. That would indicate that vmdk disk might be running from a delta file.

foreach($vm in get-vm) { get-harddisk -vm $vm| select @{N="VMname";E={$vm.name}},Filename |? {$_.FileName.Split('/')[-1] -match ".*\-[0-9]{6}\.vmdk"} }
#foreach VM in infrastructure , get all hard disks with name that matches pattern *-000000.vmdk
Days              : 0
Hours             : 0
Minutes           : 5
Seconds           : 44
Milliseconds      : 365

After a while i thought if somebody has very large inventory this could take a while so i have rewritten this using get-view

foreach($vmview in get-view -viewtype virtualmachine){ $vmview.Config.Hardware.Device | ? {$_ -is [VMware.Vim.VirtualDisk]} | %{$_.Backing | select @{N="VMname";E={$vmview.name}},Filename |?{$_.FileName.Split('/')[-1] -match ".*\-[0-9]{6}\.vmdk"} }  }
#foreach virtual machine get-view get only devices from its config that are hard disks, then select those that name matches pattern *-000000.vmdk 
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 26
Milliseconds      : 150

Those measures were taken on a 1k+ vms virtual infrastructure.
As a result you will see output with

VMname         Filename
VMa            [datastore] VMa/VMa-000001.vmdk
VMb            [datastore] VMb/VMb-000004.vmdk

I think it is worth to check if vms are running using delta vmdks from time to time, even if you do not suspect that.

Advertisements

3 thoughts on “Watch out for snapshots… l invisible snapshots ;)

  1. That’s a very good question ! 🙂 That would mean the same as the result of getting snapshot size i suppose. But since get-snapshot will not discover that snapshot we would have to use other way. I guess the easiest way is to use vsphere psdrive and check the size. Will have this in mind and will try not forget to extend the script with functionality for giving vmdk size. Currently i don’t have much free time to work on it ;( But i hope i will find some time in upcoming days/weeks.
    Greg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s