Blog Post

vCentre Useful Queries: Part I

,

After posting on twitter last week that I needed something to write a blog post about my good friend Christian Dadswell (Blog|Twitter) suggested I post the queries I wrote for him awhile back to dig him out of hole. Chris has dug me out of many a hole when I have needed advice on vSphere, Chris is a full time vSphere guru and part-time Android developer, which  he is very good at. Go and check out his BBC Browse Cast app for yourself. Not having an android phone myself I haven’t used his app, he refuses to get involved with Apple products which is a shame but if he gets enough encouragement I’m sure he could be persuaded. 

Chris needed me to get some information out of the vSphere vCentre database. Firstly he wanted a quick and dirty way of getting information from vCentre database  on VM snapshots. Snapshots are great tool that can allow you take a snapshot or ‘point in time’ view of the VM. I find it easiest to imagine vSphere snapshots to be similar to database snapshots in SQL Server. We don’t go into the specific  details of how these work here but if you create a snapshot on a VM, as the VM changes the changes are written to the snapshot. This enables you to restore the VM to the state it was when the snapshot was taken. This can be useful when applying OS patches and the like.

You can get problems  when you forget that the snapshot exists and it can fill up the space on disk. If this happens it can cause your VM to stop working properly. Chris wanted to find all VMs that had a snapshot over 14 days old. The theory behind it was if a snapshot was older than 14 days it was unlikely to ever be used to restore the VM and he could then get onto the person who created it and hopefully delete it before it causes problems.

This is the query that was used

select  e.NAME,
s.SNAPSHOT_NAME,
s.CREATE_TIME

from VPX_SNAPSHOT s
INNER JOIN VPX_ENTITY e ON s.VM_ID = e.ID
WHERE s.CREATE_TIME < GETDATE()-14
ORDER BY s.CREATE_TIME asc

I hope you find it useful. I ended up plugging this query into a SSRS report to allow all sys admins find old snapshots.

There will be a second post in this series looking at monitoring which VMs are running on what host and why that can be useful


Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating