This will shutdown your virtual machines, copy the .vhd virtual hard disk files (not snapshots) to a backup location, and then power your virtual machines back on.
Install the Windows PowerShell Feature
-
You may need to install Windows PowerShell on your Hyper-V host machine, Server Manager -> Add Features.
Learn Some PowerShell Basics
-
A PowerShell script is a plain text file with the extension .ps1.
-
To execute a PowerShell script, open Run and enter:
powershell.exe c:\myscript.ps1
-
The -noexit paramater will keep the command prompt open after the script has finished executing:
powershell.exe -noexit c:\myscript.ps1
* don't use -noexit if you're calling a script from a batch file, execution will stop at the end of the script and never return back to the batch file.
Set PowerShell Execution Policy to Allow Unsigned Local Scripts
-
If you run a PowerShell script for the first time, you'll probably encounter this error:
File C:\scripts\test.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-
help about_signing" for more details.
-
You can read the details here, or just execute the following command within PowerShell to allow your own scripts to run:
Set-ExecutionPolicy RemoteSigned
Download the Backup Scripts, Customize, and Schedule
-
-
If you unzip the files to c:\scripts\vmbackup, then most of the paths will be correct.
- It's just been brought to my attention that you need to Right-click VmBackup.bat -> Properties -> Unblock, or you'll receive an error about the script not being digitally signed. Thanks Almoonir!
-
Modify VmNamesStop.txt with the names of your virtual machines, your domain controller should be last.
-
Modify VmNamesStart.txt with the names of your virtual machines, your domain controller should be first.
-
Modify VmBackup.bat to copy your vhd files to your backup location.
-
Create a scheduled task to run VmBackup.bat regularly.
Notes (UPDATED 9/25/2008)
-
-
I ran a full backup last night and I made the classic mistake in forgetting to turn my domain controller off last, and then power it on first. To accomplish this, I created 2 lists of VMNames.txt, one for stopping the VMs (DC last) and the other for starting them (DC first).
-