Multiple Windows Server Backup Schedules using PowerShell

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″

Share

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.