Pregunta

I need to implement a backup solution for virtual machines runnin on Windows Server 2008 R2 using Powershell and PSHyperV module. The module helps loads, as it provides an easy way to get VM properties and other stuff, perform basic functions, etc.

I plan for the least downtime scenario, as the VMs in question are potentially used by clients, and they usually don't tolerate any downtime. I am aware that using Windows Server 2012 R2 hypervisor solves this problem altogether because it has live VHD merge functionality, but migration of infrastructure is a long enough process and backups don't wait.

Currently, the backups are done via save VM -> copy tree -> start VM process, which involves up to 6h downtime for the biggest VM. I am planning to use VM snapshots to lessen the downtime, as once you have performed a snapshot, you can back up the VHDs and the snapshot data elsewhere without disturbing the VM (it'll be slower, but that's all). Then I plan to save the VM, remove the snapshot (VHD merge will occur), wait until merging will complete, then start the VM, potentially reducing the VM downtime to half an hour worst case.

So far my script is able to locate VHDs of a given VM, back them up, but is unable to find the VM's snapshots location. It is possible that just traversing the tree from VHDs folder backwards will not yield me neither "Virtual Machines" nor "Snapshots" folder, so guessing is out of option.

How do I get the location of snapshot files in order to do a manual export for the VM snapshot?

¿Fue útil?

Solución

Got the data, perhaps someone would find it useful.

$vmName = "Test VM"
$vm = Get-VM $vmname
$vmGlobal = Get-WMIObject -class Msvm_VirtualSystemGlobalSettingData -namespace "root/virtualization" | where {$_.systemname -eq $vm.name}
$vmRootPath = $vmGlobal.ExternalDataRoot
$snapshotPath = $vmGlobal.SnapshotDataRoot

Then, get these paths, append "Snapshots" to snapshot path (apparently hardcoded), append "Virtual Machines" to root path, and get configuration and snapshot files. Disks could be received by calling $vm | Get-VMDisk | where {$_.DiskName -eq "Hard Disk Image"}, these contain absolute paths to the files.

This should be enough for me to get all data required to back up and restore a VM from a snapshot, even in case the original VM is destroyed due to disk loss. I'd probably have to mess up with the backed up XML to change paths, but this is a bit easier.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top