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 #31

Open kirily67 opened 7 months ago

kirily67 commented 7 months ago

At first, let me say that you made great script.

For my needs i made a few improvements.

  1. Added posibility for comments in vms.txt, in case you not want to backup a VM for some reason.
  2. I found that in case of missing VM in vms.txt, the script does not continue. Becouse of that - i added code to remove missing VM's from varable $Vms
  3. Becouse i'm a lasy man, a made my vms.txt via piping 'Get-VM | Select Name' to vms.txt. And i found that since that, from 5 VM's only one is backuped. After some investigayion found that the problem comes from trailing spaces in VM's name and the only one working is with long name...

And that's the code modification

#Original line is commented
#$Vms = Get-Content $VmList | Where-Object {$_.trim() -ne ""}
#And added new with check for '#'
$Vms = Get-Content $VmList | Where-Object {($_.trim() -ne "") -and ($_.substring(0,1) -ne "#")}

#Remove missing VM from list
$newVms = @()
ForEach ($Vm in $Vms)
{
       #Trim leading and trailing spaces in VM name
       $VM = $Vm.trim()
       $Exists = get-vm -name $Vm -ErrorAction SilentlyContinue
       If ($Exists)
       {
              $newVms = $newVms += $Vm
       }
       else {
              Write-Log -Type Err -Evt "(VM:$Vm) Missing VM"
       }
}
$Vms = $newVms
  1. Becouse my idea is after copying (not exporting) VM's to some disk, to transfer ONLY NEW files to SFTP server with a backup utility (for example rsync), i encountered the following problems:

    A) Even i do not want to keep more than one backup, you made current backup in folder named as VM name, and after that rename it, by adding date to folder name. Which in my case is a new folder for backup and is tranfered to SFTP. May be that is not so good decision?! Now i just commented renaming operations, but may be is a rasonable to keep folder name permanent in case of only one backup for VM...

    B) Using Copy-Item for copying files from original VM folders to backup folder, changes timestamps of files. Which in my case again generates a new file transfer. Thus even if i have one big vhd(x), that is not touched from long time, and some small snapshot, i must send all them to SFTP. So it will be a good improvement if timestamps of files can be preserved.

    For myself, since copying of timestamp via powershell seems to be an unnecessary complication to make list of all snapshots for VM and transfer timestamp from original to backup file, i replaced Copy-Item with RoboCopy...