
Consolidating snapshots on VMware
There are times when for one reason or another a VMware datastore fills up, it's usually because of 'fault’ from a snaphost that doesn't account for the maximum size of the disk definition. On certain occasions when the datastore is completely full, we will not even be able to delete the snapshot, Not even being able to start the machine; So we're lost. A 'solution'’ is to extend the LUN, then expand the datastore and that's it, We retried what we wanted. Sometimes this is not possible, or is it directly a ñapa; what we have to do is consolidate our disks with their snapshots on a temporary LUN and finally return everything to its original datastore without snapshots or so on, Here's the solution.
This for example could be a typical error when we have a completely full datastore, The virtual machine tries to write to the datastore but since there is not enough space we can do nothing but turn it off.
We have to make sure and know exactly which hard drives are associated with the VM with: 'grep -i filename /vmfs/volumes/DATASTORE_VIEJO/MV/*.vmx | grep -i vmdk’
Now we will check the space we will need at least in another datastore to consolidate the disks, with 'ls -lah /vmfs/volumes/DATASTORE_VIEJO/MV/*flat.vmdk'. We already know that for this example we need 15Gb.
Well, Started, We check the disks we have with 'grep -i filename *.vmx’ in the datastore of the machine that has the snapshot. We look at the name of the albums. The disk in this case is called 'w2k7pro-000001.vmdk, which is the one generated by the snapshot.
We check the disk CID in the descriptor of each snapshot. We verify that the CID of the current disk is 'abccb37f’ and the top disk named 'W2K7Pro.vMDK’ is '663e241a'. This must be done until the base disc is reached, In my case it will be that, Why do I have only one snapshot, so OK. Check one by one until you check that your chain of discs is correct,
Now we create a folder in a datastore that we have enough space to put the base disk with the consolidated snapshots, in my case it was 15Gb, so 'mkdir /vmfs/volumes/DATASTORE_NUEVO/FOLDER/'.
With the following command we will consolidate the disk with its snapshot into a temporary datastore: 'vmkfstools -i /vmfs/volumes/DATASTORE_VIEJO/MV/disco-snapshot.vmdk /vmfs/volumes/DATASTORE_NUEVO/FOLDER/consolidated-disk.vmdk’ And wait for it to end, that depending on the size of the disk to be consolidated and the infrastructure we have can vary greatly.
We edit the affected VM, We remove the link from the old album and add the newly created album. Now, We must turn on the machine and check that everything is correct and we do not have any loss of information.
We need to delete the base disk and its snapshots, running 'grep -A2 parentFile disco-snapshot.vmdk’ We will know which disks we have to delete since it shows us the pointers between the disks.
We delete all disks with 'rm /PATH/disco.vmdk’ and we confirm with 'and'.
Now we clone the newly created disk to its correct location with 'vmkfstools -i /vmfs/volumes/DATASTORE_NUEVO/FOLDER/consolidated-disk.vmdk /vmfs/volumes/DATASTORE_VIEJO/MV/disk.vmdk’
We do the same, We unattach the disk that we had added to test and we put the correct one in. Turn the machine on again and check that everything is still correct and we have no loss of information. We turn it off.
Now we need to delete the snapshosts database, We can rename the .vmsd file and delete it later.
We remove the machine from the inventory.
And we add it back to the inventory and we will verify that it no longer has snapshots associated with it, they are all consolidated and the machine could already be turned on in its original datastore!
Reference: VMware KB 1007849