A couple days ago I was asked the question “An admin deleted the vmdk file associated with a VM, there are no snapshots or backups of the VM . Can we restore this VM somehow?“. I believe in backups, I like to have my VM’s backed up so that I can depend on them for events just like this very issue. At first I was stumped, until the {vm-name}.flat.vmdk was mentioned. That’s when I remembered a method to recover a VM using the vm-flat.vmdk file that I had actually done 2-3 years ago.
Example preparation
For this example I’ve created a Server 2012 virtual machine (called Win2012) and placed a text file on the desktop called “Important Info”. I then deleted all the files associated with that VM with the exception of the Win2012-flat.vmdk file, as seen in the p_w_picpath at top.
After the files had been deleted I tried to power up the VM knowing it would not and received this error.
Ok, now on to how to restore a VM with a missing .VMDK file.
How to Recover a VM using a vm-flat.vmdk file
I created a new VM called Recovery with the same specs as my Win2012 server (2vCPU, 4GB RAM, 40GB HHD).
Enable SSH on the host and logged in via PuTTy (or WinSCP) and verified the contents of Win2012 folder:
cd /vmfs/volumes/vmNFS02/Win2012/
Then navigate to the Recovery VM folder.
cd ../Recovery/
Rename the original Recovery-flat.vmdk file to Recovery-flat.vmdk.bak
mv Recovery-flat.vmdk Recovery-flat.vmdk.bak
Now just copy the Win2012-flat.vmdk file from the Win2012 folder over to the Recovery folder (Note: This step could take several minutes):
cp /vmfs/volumes/vmNFS02/Win2012/Win2012-flat.vmdk Recovery-flat.vmdk
Finally, power up the new Recovery VM and your old VM (Win2012) should be back online good as new!
You can also go back and delete the Recovery-flat.vmdk.bak file as it won’t be needed.
So even though restoring a VM from a -flat.vmdk file is pretty easy it isn’t my recommended method, you’re far better protected with good, reliable backups, then on hoping that the -flat.vmdk file is still laying around somewhere.
转载于:https://blog.51cto.com/549687/1977451