Digressive / HyperV-Backup-Utility

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

Some feature requests #28

Open TripleNico opened 1 year ago

TripleNico commented 1 year ago

First of all let me say i really like you're way of scripting and love to see your enthusiasm in your work.

Last year i've made my own version of you script then because i needed to be more lightweight and there were a few things not available then like the -LowDisk switch. But today i've check what you've been working at and i'm impressed, it almost fits my need and i know it's a lot to ask (since i can do it myself) but could you consider to add these features?

... do stuff ...

$elapsedTime = $(get-date) - $StartTime $totalTime = "{0:HH:mm:ss}" -f ([datetime]$elapsedTime.Ticks) SendMail "VM $Vm done" "Processed VM: $Vm in $totalTime" Write-Log -Type Info "-------------------------- Done processing VM: $Vm in $totalTime --------------------------------" Write-Log -Type Info ""

- [x] Switch -PrintVMInfo: this features simply printout all info it could find. For example what i use:
```powershell
## Print info per VM.
ForEach ($Vm in $Vms) {
    #Get SystemInfo
    Try {
        #Log VM specs
        $VhdSize = Get-VHD -Path $($Vm | Get-VMHardDiskDrive | Select-Object -ExpandProperty "Path") | Select-Object @{Name = "FileSizeGB"; Expression = { [math]::ceiling( $_.FileSize / 1GB ) } }, @{Name = "M
        Write-Output "VM [$Vm] has [$((Get-VMProcessor $Vm).Count)] CPU cores, [$([math]::ceiling((Get-VMMemory $Vm).Startup / 1gb))GB] RAM and Storage [CurrentFileSizeGB = $($VhdSize.FileSizeGB)GB - MaxSizeG
    }
    Catch {
        Write-Error "Error during Systeminfo: $($_.Exception.Message)"
    }
}   

... later on ...

Let's start the BackupServer if it's not running

If (Test-Connection -ComputerName "IP/Hostname" -Count 2 -Delay 5 -Quiet ) {

Backup server responded meaning it's already online.

Write-Log -Type Info -Evt "BackupServer is online, waiting 30 seconds just to be sure..."
Start-Sleep 30

} else { Write-Log -Type Info -Evt "Sending magic packet to BackupServer [$BackupServerMacAddress]" Invoke-WakeOnLan -MacAddress "$BackupServerMacAddress" -Verbose

Now wait until backupserver is online

Write-Log -Type Info -Evt "Waiting for BackupServer to come online..."
If (Test-Connection -ComputerName "IP/Hostname" -Count 12 -Delay 10 -Quiet ) {
    #Backupserver responded now give some extra time for Windows to fully be up and running
    Write-Log -Type Info -Evt "BackupServer is online, waiting 2 more minutes for Windows to complete..."
    Start-Sleep 120
}
else {
    Write-Log -Type Err -Evt "Backupserver failed to respond within 2 minutes. BACkUP SCRIPT WILL NOT CONTINUE"
    $MailBody = Get-Content -Path $Log | Out-String
    SendMail "VM Backup: Failed to start backupserver" $MailBody
    Write-Log -Type Info -Evt "Log finished"
    Exit
}

}

... When done, shutdown ...

Now shutdown the backup server

Try { Write-Log -Type Info -Evt "Waiting for BackupServer to shutdown..." Stop-Computer -ComputerName "IP/Hostname" -Credential $credObject -Force

Wait until backupserver is down

While ( Test-Connection "IP/Hostname" -Quiet -Count 1) {
    Start-Sleep -Seconds 10
    #Check if we are waiting more than two minutes
    if ($timer.Elapsed.TotalSeconds -gt 120) {
        Write-Log -Type Err -Evt "Backupserver shutdown did not complete before timeout period."
        Break
    }
}
#Double check if server is down or Watchdog has kicked in
if (-Not (Test-Connection "IP/Hostname" -Quiet -Count 2)) {
    Write-Log -Type Info -Evt "BackupServer succesfully shutdown"
}

} catch { Write-Log -Type Err -Evt "Error backup shutdown: $($_.Exception.Message)" }



Those are the points i have, not to bad right ;-)

Again, thanks for all your effort so far!
Digressive commented 1 year ago

Thank you for this, very interesting! I'll work on getting these enhancements implemented in future.

Digressive commented 10 months ago

I'm adding all the suggestions here except for the Wake On Lan option for the time being. WOL feels a little out of scope but I'm willing to add it if there's a demand.