I found this Backup script posted by Augagneur Alexandre in the Powershell script repository,
As I’m new to Powershell it looked like a good starting point for my needs.
I modified it to accommodate my environment and it works great if I run it manually.
I wanted it to run on a daily schedule so I tried using the Windows Task Scheduler ,
The task ran but not the backup job.
From Task History
Task Scheduler launched action"C:\Users\wfcadmin\Documents\WindowsPowerShell\ExchSrvBareMetalBkup.ps1" in instance "{192de11b-6ed0-45c8-b596-f4bb8e4fc1fb}" of task"\ExchangeSrvBackup".
Task Scheduler launch task "\ExchangeSrvBackup" , instance"C:\Program Files\Idera\PowerShellPlus\Internal\PSPEditor.exe" with process ID 8672.
Task Scheduler successfully completed task "\ExchangeSrvBackup" , instance"{192de11b-6ed0-45c8-b596-f4bb8e4fc1fb}" , action "C:\Program Files\Idera\PowerShellPlus\Internal\PSPEditor.exe" with return code 0.
Task Scheduler successfully finished"{192de11b-6ed0-45c8-b596-f4bb8e4fc1fb}" instance of the"\ExchangeSrvBackup" task for user "WFC\wfcadmin".
Then I remembered that PS has Set-WBSchedule
So I added it to the last line in the script, it should be setting the scheduled time to run the backup.
I have verified the schedule is set
PS C:\Users\wfcadmin> Set-WBSchedule -Policy $WBPolicy -Schedule 10:00
Thursday, January 10, 2013 10:00:00 AM
And the policy settings are correct
Results from $WBPolicy
PS C:\Users\wfcadmin> $WBPolicy
Schedule : {1/10/2013 10:00:00 AM}
BackupTargets : {\\SaraMarIII\E\ExchangeSrvBkup\01102013_0949}
VolumesToBackup : {MailData (D:)}
FilesSpecsToBackup :
FilesSpecsToExclude :
BMR : True
SystemState : False
VssBackupOptions : VssCopyBackup
So the schedule is set but the job does not start at the scheduled time.
Is there an obvious reason why this is not working?
Thank you in advance for any and all responses.
Gil
Backup Sctipt
#------------------------------------------------------------------
#Variables
#------------------------------------------------------------------
#Files server
$Nas = "\\SaraMarIII\E"
#Root folder
$HomeBkpDir = ($Nas+"\ExchangeSrvBkup")
#Backup folder
$Filename = Get-Date -Format MMddyyyy_hhmm
#Number of backup to retain (value "0" disable rotation)
$MaxBackup = 1
#List uncritical volumes
$Volumes = Get-WBVolume -AllVolumes | Where-Object { $_.Property -notlike "Critical*" }
#------------------------------------------------------------------
#Function to compare the number of folders to retain with
#$MaxBackup (No called if $MaxBackup equals 0)
#------------------------------------------------------------------
function Rotation()
{
#List all backup folders
$Backups = @(Get-ChildItem -Path $HomeBkpDir\*)
#Number of backups folders
$NbrBackups = $Backups.count
$i = 0
#Delete oldest backup folders
while ($NbrBackups -ge $MaxBackup)
{
$Backups[$i] | Remove-Item -Force -Recurse -Confirm:$false
$NbrBackups -= 1
$i++
}
}
#------------------------------------------------------------------
#Main
#------------------------------------------------------------------
#Execute rotation if enabled
if ($MaxBackup -ne 0)
{
Rotation
}
#Backup folder creation
New-Item ($HomeBkpDir+"\"+$Filename) -Type Directory | Out-Null
#Create new Backup Policy
$WBPolicy = New-WBPolicy
#Enable BareMetal functionnality (system state included)
Add-WBBareMetalRecovery -Policy $WBPolicy | Out-Null
#Add backup target
$BackupLocation = New-WBBackupTarget -network ($HomeBkpDir+"\"+$Filename)
Add-WBBackupTarget -Policy $WBPolicy -Target $BackupLocation -force | Out-Null
#Add uncritical volumes
if ($Volumes -ne $null)
{
Add-WBVolume -Policy $WBPolicy -Volume $Volumes | Out-null
}
$WBPolicy | Out-Null
#Set Backup Schedule
Set-WBSchedule -Policy $WBPolicy -Schedule 10:00