PowerShell script exchange
Post Reply
sidavid
Enthusiast
Posts: 48
Liked: 1 time
Joined: Jan 01, 2006 1:01 am
Contact:

Backup Copy Job Schedule

Post by sidavid »

Hi,

I want to specify Schedule for Backup Copy Jobs but I do not know how to start. I have read the PDF powershell. I think I need to use the Set-VBRJobScheduleOptions command, but how?

Get-VBRJob -Name OFFSITE-DAILY* | foreach {
$vbrjobname = $_.Name
Write-Host $vbrjobname
Get-VBRJob -Name $vbrjobname | Set-VBRJobScheduleOptions -Options $"Schedule Options"
}

How to use Set-VBRJobScheduleOptions -Options $"Schedule Options" to set the schedule I want to be enable:
Sun from 06:00PM to Mon 03:00PM
Tue, Wed, Thu, Fri, Sat from 12:01AM to 03:00PM

Thanks a lot
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Backup Copy Job Schedule

Post by tsightler »

As mentioned in my reply to your other query, working with Backup Copies is a little different from other jobs since they always run in continuous mode but indeed you can use Set-VBRJobScheduleOptions to set the parameters.

Manipulating the "Allowed to run" schedule for continuous jobs via Powershell is pretty easy, however, there's one big caveat. While it's easy to change the schedule assuming the "During the following time periods" options is already selected in the GUI, so far I've been unable to figure out how to switch from the "Any Time (continous)" mode that is the default using Powershell. Assuming that the "During the following time periods" option is already selected in the GUI, then the following method should work fine. If any of the other Powershell gurus out there know how to actually enable the backup window option from Powershell I would like to know how.

The "Allowed to run" property is defined by an XML properly stored in the OptionsContinous.Schedule attribute so by creating such an object with the settings we want we can update the jobs with the new schedule. Each day is represented by a string of 0's and 1's for each of the 24 hours starting from midnight. A "0" means the job can run, while a "1" means the job is blocked from processing during that time. Knowing that infomation we can build our attribute. The code below build a schedule that matches your request (I think):

Code: Select all

# Create Allowed Schedule Property
$AllowedtoRun = "<scheduler><Sunday>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0</Sunday><Monday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Tuesday><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Wednesday><Thursday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Friday><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Saturday></scheduler>"

Get-VBRJob -Name "OFFSITE-DAILY*" | foreach {
   Write-Host $_.Name
   # Disable the Job
   $_.DisableScheduler()
   # Wait for the job to actually stop
   while (!$_.IsStopped()) {}
   $ScheduleOptions = $_.ScheduleOptions
   $ScheduleOptions.OptionsContinuous.Schedule = $AllowedtoRun
   Set-VBRJobScheduleOptions -Job $_ -Options $ScheduleOptions
   $_.EnableScheduler()
}
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Backup Copy Job Schedule

Post by tsightler »

OK, I got it, there's a parameter called "BackupCopyJobCanRunAnyTime" that controls the GUI options (wow it took some digging to find that). This is a simple string value set to either "True" or "False" and when set properly will change the GUI to show the proper option, so here's modified code that will properly set the window as well as the GUI to reflect the selected options.

Code: Select all

# Create Allowed Schedule Property
$AllowedtoRun = "<scheduler><Sunday>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0</Sunday><Monday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Tuesday><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Wednesday><Thursday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Friday><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Saturday></scheduler>"


Get-VBRJob -Name "OFFSITE-DAILY*" | foreach {
   Write-Host $_.Name
   # Disable the Job
   $_.DisableScheduler()
   # Wait for the job to actually stop
   while (!$_.IsStopped()) {}
   $Options = $_.Options
   $Options.Options.RootNode.BackupCopyJobCanRunAnyTime = "False"
   $ScheduleOptions = $_.ScheduleOptions
   $ScheduleOptions.OptionsContinuous.Schedule = $AllowedtoRun
   Set-VBRJobScheduleOptions -Job $_ -Options $ScheduleOptions
   $_.SetOptions($Options)
   $_.EnableScheduler()
}
sidavid
Enthusiast
Posts: 48
Liked: 1 time
Joined: Jan 01, 2006 1:01 am
Contact:

Re: Backup Copy Job Schedule

Post by sidavid »

Hi

Everything is working except the line $Options.Options.RootNode.BackupCopyJobCanRunAnyTime = "False"

When I run the script, I have the following error:

Code: Select all

Property 'BackupCopyJobCanRunAnyTime' cannot be found on this object; make sure
 it exists and is settable.
At C:\Veeam-Scripts\Extra-Scripts\veeam\dd.ps1:9 char:27
+ $Options.Options.RootNode. <<<< BackupCopyJobCanRunAnyTime = "False"
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException
Many thnaks
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Backup Copy Job Schedule

Post by tsightler »

Sorry, I think that was a mistake on my part as the value of BackupCopyJobCanRunAnyTime and be set with a boolean in JobOptions which is probably the more correct way. Try this code at let me know if it works, it works fine in my test lab:

Code: Select all

# Create Allowed Schedule Property
$AllowedtoRun = "<scheduler><Sunday>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0</Sunday><Monday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Tuesday><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Wednesday><Thursday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Friday><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1</Saturday></scheduler>"


Get-VBRJob -Name "OFFSITE-DAILY*" | foreach {
   Write-Host $_.Name
   # Disable the Job
   $_.DisableScheduler()
   # Wait for the job to actually stop
   while (!$_.IsStopped()) {}
   $Options = $_.Options
   $Options.JobOptions.BackupCopyJobCanRunAnyTime = $false
   $_.SetOptions($Options)
   $ScheduleOptions = $_.ScheduleOptions
   $ScheduleOptions.OptionsContinuous.Schedule = $AllowedtoRun
   Set-VBRJobScheduleOptions -Job $_ -Options $ScheduleOptions
   $_.EnableScheduler()
}
If for some reason it doesn't work can you verify that you are running V7 Patch 1?
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests