Digressive / HyperV-Backup-Utility

Flexible Hyper-V Backup Utility
https://gal.vin/posts/vm-backup-for-hyper-v/
MIT License
125 stars 40 forks source link

New Featurerequest, add parameter for Export-VM #34

Closed bacardischmal closed 4 months ago

bacardischmal commented 6 months ago

Hi, i had trouble to export some VMs, they had lags/freezes at the beginning from the exports, it took about 30 to 90 sec for the VM to be unavailable. I found out its because of the type of export of the VM

I added quick and dirty on this line the parameter CaptureLiveState and it worked like a charm. Line 1400 $Vm | Export-VM -Path "$WorkDir" -ErrorAction 'Stop' to $Vm | Export-VM -Path "$WorkDir" -ErrorAction 'Stop' -CaptureLiveState CaptureDataConsistentState

Would it make sense to integrate the export selection into the script call or is it not a good idea to change the kind of export?

Digressive commented 6 months ago

@bacardischmal Hi there, thanks for mentioning this - I'll do some tests on my end. What are the VMs doing that were lagging/freezing? It might help. Thanks again

Digressive commented 6 months ago

@bacardischmal I just tested this with the new additions and my tests all failed so I'm reluctant to make this change until I understand exactly what is going on.

Since it's working well for you, that's great! Any more information you can provide about the VMs and their workload would be helpful.

bacardischmal commented 6 months ago

What did at your test fail?

The freeze is at the moment the export starts, you can recognize it from the Hyper V-Manager, Open the VM and open the system clock in taskbar to see the seconds and watch it, it stops running for several seconds. Same problem happend when you export a VM from the Hyper V-Manager. I think its something because of the IO Performance, I did a export from a SSD to HDD the lag is about 90sec, did the same export from a ssd to a ssd 15 sec of lag. I can reproduce it on different systems, some of the VMs are Terminalserver and when there is a client connected the RDP session fezzes at this moment and you can do nothing, you get no disconnect/reconnect/blackscreen ect. at the time, only no response of the RDP. I tested it on a w2k16 and w2k19 standard server.

Perhaps there should be a possibility to pass the three parameters to the export method and not a fixed in the script? https://learn.microsoft.com/en-us/powershell/module/hyper-v/export-vm?view=windowsserver2022-ps

Digressive commented 6 months ago

@bacardischmal My testing fails at the Export-VM stage with the error: Export-Vm : [VM Name] failed to export. Failed to export virtual machine. Can not create an application consistent checkpoint.

This is with a Windows Server 2022 VM. Creating Checkpoints works via the Hyper-V mmc.

I did test with "-CaptureLiveState CaptureCrashConsistentState" and "-CaptureLiveState CaptureDataConsistentState" and they both worked.

I'm going to add an option to the script so that the user and specify the -CaptureLiveState {CaptureCrashConsistentState | CaptureSavedState | CaptureDataConsistentState} option, as you suggested.