Snapshot

VM snapshot needs consolidation

When a snapshot didn’t commit properly, it can happen that the snapshot manager in the vCenter server shows no snapshot(s), but that there are still active delta files on the datastore. These ‘hidden’ snapshot can cause the datastore to run out of space.

To report these ‘hidden’ snapshots (prior vSphere 5), I created a script that searches all the datastores  for ‘*.delta’ files and reported them by mail.

In vSphere 5 you have a new feature that reports and make it possible to consolidate these  ‘hidden’ snapshot(s). In vSphere 5 you get  a warning ‘Virtual machine disks consolidation is needed’ when the virtual machine snapshot consolidation has failed.

image

The snapshot manager shows no snapshots but there are delta files present on the datastore(s).

image image

In the vCenter server on the Virtual Machines tab you can enable the field “Needs Consolidation” to filter all the VMs that needs consolidation.

image

To consolidate the snapshot, right-click the virtual machine and choose Snapshot - Consolidate.

image

Confirm the consolidate

image

Check the datastore and all the delta files are consolidated

image

 

With PowerCLI you can use the following one liner to list all the VMs that needs consolidation (thanks to Luc Dekens ):

Get-VM | where {$_.ExtensionData.Runtime.consolidationNeeded} | Select Name
 

VMware ESXi 5 snapshot changes

In ESX(i) 3.x and 4.x snapshots files are default created in the virtual machine’s working directory (home directory). The working directory is the same directory as the were the virtual machine configuration (*.vmx) file is stored. 

snapshot-working basic esxi4

 

In this example a VM called “test” that has two disks (VMDK’s) placed on two datastores. The first disk is created on the VMFS01 datastore and the second disk is created on the VMFS02 datastore.  When a snapshot is created,  the VM “test”, the snapshot redolog (-delta.vmdk) files are place in the working directory (home directory). So the snapshots files are created on datastore VMFS01.

 

snapshot-working esxi4

 

In ESXi 5 the snapshot delta disks are stored in the same home folder as the base disk. On every disk a snapshot file is created.

snapshot-working esxi5

 

I have seen VMware ESX(i) 3.x and 4.x environments were only the working directory (home directory) is sized to store snapshot files . The other datastores didn’t have enough room for storing snapshot files.  So be sure before upgrading to vSphere 5 that all the datastores have enough free space to store snapshot files!

The snapshot location can changed in ESXi 5 but when performing a Storage vMotion, all the snapshot deltas will get migrated to the same folder as the VM’s base disk on the destination. 

Be sure to check this before upgrading to VMware vSphere 5!

 

More Information:

VMware Powershell Healthcheck script

Healthcheck is a Powershell script that reports information like snapshots, VMware tools version, datastore space, CDROM and/or floppy drives connected etc. to HTML and e-mail the output to a person or distribution list.

Reason for creating this script:

As VMware Consultant I see a lot of common problems in VMware environments like:

- Snapshots are enabled and forgot the commit to the VM.

- Datastores are almost full (for example if snapshots are enabled)

- VMware tools versions are different

- CDROM and floppy drives are still mounted to the VM

- Virtual Machines have CPU and Memory limits or reservations (VMs are swapping)

- In the VM, the VMware Tools timesync option is not enabled

In the Virtual Infrastructure Client (VIC) it is difficult to see this sort of information. By creating a Powershell script,  I can do a quick inventory.  In a lot of VMware environments I created a scheduled tasks, so the script runs once a week and sent to HTML rapport to the administrator.

What does the script:

I wrote a Powershell script with HELP from the VMTN community that makes a HTML file and sent the output by e-mail to a person or distribution list.  The Healthcheck script does the following checks:

- VMware ESX hardware

- VMware ESX versions

- VMware VirtualCenter versions

- Active snapshots

- CDROM and Floppy drive(s) mounted to the VM

- Datastore information like capacity, free space and the percentage free space

- VirtualMachine (VM) information like VMware tools version, CPU, Memory reservations and limits etc.

- On what VMs VMware Tools timesync is not enabled

Requirements:

The following software must be installed:

Microsoft Powershell 1.0 (http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx)

VMware Infrastucture (VI) toolkit for Windows 1.0

http://www.vmware.com/download/sdk/

Set the ExecutionPolicy in Windows Powershell to RemoteSigned by using the following command:

set-ExecutionPolicy RemoteSigned

Installation:

- Unzip the Healthcheck.zip script to a directory on the VC server for example.

- When the ZIP if unpacked there are two files:

- Healthcheck.ps1, this is the Powershell script

- Style.CSS, controls the HTML layout

Configuration:

- Edit the Powershell.ps1 file

edit the following variables:

$vcserver=”localhost”

Enter the VC server, if you execute the script on the VC server you can use the localhost name

$filelocation=”D:\temp\Healthcheck.htm”
Specify the location where to store the HTML output

$enablemail=”yes”
Enable (yes) or disable (no) to sent the script by e-mail

$smtpServer = “mail.ivobeerens.nl”
Specify the SMTP server in your network

$mailfrom = “VMware Healtcheck <powershell@ivobeerens.nl>”
Specify the from field

$mailto = ivo@ivobeerens.nl

Specify the address where the e-mail to sent  to

Usage:

Manually run the Healthcheck.ps1 script”:

1. Open Powershell

2. Browse to the directory where the Healthcheck.ps1 script resides

3. enter the command:

./Healthcheck.ps1

To create a schedule task in for example Windows 2003 use the following syntax in the run property:
Powershell -command “& ‘path\Healthcheck.ps1′
edit the path

Powershell -command “& ‘path\Healthcheck.ps1′

edit the path .

Future:

- List Orphaned VMDK’s

- Add performance information like VM usage

- Check timesync on the VMware hosts

Happy testing :-)

Download Link: Healthcheck script

The script is posted on the VMware Powershell contest forum, link

Some screenshots of the HTML output:

 

1JPG

2

3