Howto recover snapshots

Hyper-V Snapshots work by using differencing disks. After you (accidentally) removed your VM from Hyper-V Manger you may realize you have important data in a snapshot.

The Snapshot file has an extension .AVHD. As you might have taken multiple snapshots the dependency might look like this.

Original.vhd->Snapshot1.avhd->Snapshot2.avhd->...->SnapshotN.avhd.

You cannot easily rebuild a VM with this Snapshot chain. You could modify a new VM Settings to point to the SnapshotN.avhd, though, and be able to start the VM.

To recover this chain, you need to merge this chain into either a new vdh or recursive up into the Original.vhd.

Below methods require to specify the avhd file. The Hyper-V Manager Option "Edit Disk" only displays this file type since R2. So you may need to rename the .avhd to .vhd to be able to select it.

 

1. Merging into a new VHD.

The preferred method if you have enough disk space. Merging a dynamic vhd, may theoretically result in a file as big as the sum of all .avhd's + Original.vhd.

- In Hyper-V Manager, use "Edit Disk", select the .avhd you want to merge. Most likely the last in the chain

- Next, Select Merge, To a new virtual hard disk, Pick a path&name, Select dynamic or fixed as needed.

- Next, Finish. This might take some time as all data files need to be copied into the new.vhd

 

2. Merging into the Original.vhd (2 possible Methods)

2.1 Merging into the Original.vhd using Diskpart

 - Start an elevated CMD Prompt. Run Diskpart

 - Within Diskpart select the last Snapshot. “select vdisk file=<path>\SnapshotN.avhd

 (You need to know how many avhd childs the chain has to specify the Depth. You cannot specify more. If you specify less, the merge will happen to a Snapshot in between, and you need to restart from there. vdisk detail can give you the name of the direct predecessor)

 - Within Diskpart merge with. “merge vdisk depth=N

2.2 Merging into the Original.vhd using Hyper-V Manager

 - In Hyper-V Manager, use "Edit Disk", select the .avhd you want to merge. Most likely the last in the chain

- Next, Select Merge, To the parent virtual disk. Note, the parent is actually only one level above in the chain, so might be snapshotN-1.avhd.

- Next, Note the name of the parent disk that we will merge to. If this is a .avhd, you need to later pick that one and merge it, until you merged with Original.vhd

- Finish, This will merge one avhd with its parent. It the parent is again a .avhd, you need to start over with the parent until you reach the Original.vhd

 

Note that a differencing disk (what a .avhd essentially is) contains a absolute and relative path to its parent disk. This location is used when you merge the disk with it's parent. So when you want to merge files you copied away as a backup, bear in mind that the merge may actually modify your originals.

Cheers

-Robert