Windows Server Backup is a very useful and free product and you easily backup files, applications (Exchange, SQL) and Hyper-V VMs. A big disadvantage is that you ca only schedule one Job to run only daily.
Here comes our favorite PowerShell, combined once again with the Task Scheduler, to give us more options.
My problem was that I wanted to backup some VMs daily and some VMs weekly. So I created two PowerShell scripts and two Task Scheduler Jobs.
The PowerShell script to backup VMs:
$policy = New-WBPolicy Import-Csv C:vms.txt | foreach { Get-WBVirtualMachine | ? VMName -eq $_.name | Add-WBVirtualMachine -Policy $policy } Set-WBVSSBackupOptions -POLICY $policy -VSSFULLBACKUP $target = New-WBBackupTarget –VolumePath W: Add-WBBackupTarget -Policy $policy -Target $target Start-WBBackup -Policy $policy
The above script reads text file that has a list with the Virtual Machines names, the c:vms.txt, and starts the backup to the W: Drive.
If you just want to backup one VM alter the 2nd line with
Get-WBVirtualMachine | ? VMName -eq vmName | Add-WBVirtualMachine -Policy $policy
To backup Drives or/and Folders use this script:
$policy = New-WBPolicy $directory1 = NEW-WBFileSpec -FileSpec "C:" $directory2 = NEW-WBFileSpec -FileSpec "D:" $directories = $directory1,$directory2 Add-WBFileSpec -POLICY $policy -fileSpec $directories Set-WBVSSBackupOptions -POLICY $policy -VSSFULLBACKUP $target = New-WBBackupTarget –VolumePath W: Add-WBBackupTarget -Policy $policy -Target $target Start-WBBackup -Policy $policy
To add the SystemState to the backup Job add this line:
Add-WBSystemState -Policy $policy
To check the current running Backup job you can run
Get-WBJob
To check the previous Backup job you can run:
Get-WBJob -Previous 1
Finally create a Task and attach the PowerShell script. Here you will find the powershell.exe “C:WindowsSystem32WindowsPowerShellv1.0″
Pantelis Apostolidis is a Sr. Specialist, Azure at Microsoft and a former Microsoft Azure MVP. For the last 20 years, Pantelis has been involved to major cloud projects in Greece and abroad, helping companies to adopt and deploy cloud technologies, driving business value. He is entitled to a lot of Microsoft Expert Certifications, demonstrating his proven experience in delivering high quality solutions. He is an author, blogger and he is acting as a spokesperson for conferences, workshops and webinars. He is also an active member of several communities as a moderator in azureheads.gr and autoexec.gr. Follow him on Twitter @papostolidis.
Hi ,
Nice post. Kindly give some information how to take the back of of multiple physical server .