PowerShell: Backup your running Hyper-V Virtual Machines
If your like every one else including me its been a complete drag attempting to get clients to allow you to shut down Virtual Machines that are in production to allow you to back them up. Windows Server 2012 R2 (a free upgrade of Windows Server 2012) can be upgraded remotely using RDP without too much risk. I competed 4 Hyper-V Hosts Friday night without issue. The upgraded is pretty fast but we had to migrate the running VMs prior to the upgrade, and it too about an hour to bring the the new 2012 R2 Hyper-V hosts current with all Security and Hot Fixes (132 patches) .
Set-VMBackup.ps1
We have the backups using task scheduler, since we have multiple Hyper-V hosts, we created the schedule once then exported to xml, and imported the task on all additional Hyper-V Hosts.
Also, since the VMs rarely change we keep two backups locally and the rest are moved to the SAN in this case a NetApp for two weeks and copied to tape. Note: You only need to modify the drive and root folder, if the folder does not exist it will be created.
PowerShell Script
<# Set-VMBackup.ps1 #> #Get date string $timestamp = Get-Date -UFormat "%Y%m%d" #Change the Drive / Folder where the exports should be stored $BackupPath = “D:\VMBackup\$timestamp” #Export running VMs to Export path GET-VM | where {$_.state -eq ‘running’} | Export-VM -Path $BackupPath
Download http://1drv.ms/1PPFoUg
Ivan