PowerShell script exchange
Post Reply
ekisner
Expert
Posts: 203
Liked: 34 times
Joined: Jul 26, 2012 8:04 pm
Full Name: Erik Kisner
Contact:

Editing Backup Windows

Post by ekisner »

So I'm trying to do a bulk update on a number of jobs. Specifically, I'd like to update the schedule and block out some time periods for all jobs.

I can get the jobs:

Code: Select all

$jobs = get-vbrjobs | where {$_.name -like "specific*"}
I can get the schedules:

Code: Select all

get-vbrjobs | where {$_.name -like "specific*"} | foreach-object { $sched = get-vbrjobscheduleoptions; $sched.OptionsPeriodically.Schedule | write-output};
And I could change the schedule (which I see is just a system.string) via set-vbrjobscheduleoptions.

Unfortunately, I can't seem to discern how the schedule works. I see it's an XML string, and that each day has a number of comma-delimited zeros. But, comparing different job schedules to each other doesn't seem to be shedding any light on the matter - I would have expected to see some 1s, or a varying number of zeros... but nothing seems to be different.

If I wanted to block out 10pm to 5am, what would I edit in the string to do so? Since it's the same for all jobs mentioned, I could just enter the string as a variable and just punch that in, rather than editing the existing.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Editing Backup Windows

Post by veremin »

Could elaborate on it a little bit: do you want to specify allowed backup window and also to terminate the job in case it exceeds allocated period? Or the job is scheduled to run every X minutes/hours and you’re willing to set time interval during which the job shouldn’t be executed?

Thanks.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Editing Backup Windows

Post by veremin » 1 person likes this post

Do you want to specify allowed backup window and also to terminate the job in case it exceeds allocated period?
Generally speaking, the BackupWindow parameter is represented by long string containing days of the week, as well as, numbers. There are 24 (hours) numbers between each pair of the days. Number might be either 1, if the job run is denied during it, or 0, if it’s allowed.

For instance, the following script will set a backup window(0-4, Sunday). The job exceeding it should be termitated:

Code: Select all

asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Name of your Job"
$ScheduleOptions = $Job.GetScheduleOptions()
$ScheduleOptions.OptionsBackupWindow.Isenabled = $True
$ScheduleOptions.OptionsBackupWindow.BackupWindow = "<scheduler><Sunday>1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Sunday><Monday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Tuesday><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Wednesday><Thursday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Friday><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Saturday></scheduler>"
Set-VBRJobScheduleOptions -job $Job -Options $ScheduleOptions 
Hope this helps.
Thanks.
ekisner
Expert
Posts: 203
Liked: 34 times
Joined: Jul 26, 2012 8:04 pm
Full Name: Erik Kisner
Contact:

Re: Editing Backup Windows

Post by ekisner »

Thank you v.Eremin!

Specifically, I don't need to terminate a job outside of the window, I just want to prevent one from starting outside of the allowable time period.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Editing Backup Windows

Post by veremin »

Ok, I’ve got you point. In general, there are two quite similar scripts.

This one will specify the so-called "allowed" backup window. If a job exceeds allocated period, it will be terminated. This script should be used if one of the following options is ticked: Run the job automatically daily at this time, monthly at this time.

The following example has a time interval between 0 and 4 am, Sunday, as a backup window:

Code: Select all

asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Name of your Job"
$ScheduleOptions = $Job.GetScheduleOptions()
$ScheduleOptions.OptionsBackupWindow.Isenabled = $True
$ScheduleOptions.OptionsBackupWindow.BackupWindow = "<scheduler><Sunday>1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Sunday><Monday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Monday><Tuesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Tuesday><Wednesday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Wednesday><Thursday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Thursday><Friday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Friday><Saturday>0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0</Saturday></scheduler>"
Set-VBRJobScheduleOptions -job $Job -Options $ScheduleOptions 
The other one will set a window during whcih execution of a given job will be prohibited (22 00 – 05 00, all days). It should be used if "Run the job automatically periodically" option is enabled:

Code: Select all

asnp VeeamPSSnapin
$Job = Get-VBRJob -name "Name of your job"
$ScheduleOptions = $Job.GetScheduleOptions()
$ScheduleOptions.OptionsPeriodically.schedule = "<scheduler><Sunday>1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1</Sunday><Monday>1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1</Monday><Tuesday>1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1</Tuesday><Wednesday>1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1</Wednesday><Thursday>1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1</Thursday><Friday>1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1</Friday><Saturday>1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1</Saturday></scheduler>"
Set-VBRJobScheduleOptions -job $Job -Options $ScheduleOptions


Hope this helps.
Thanks.
marius roma
Veteran
Posts: 459
Liked: 5 times
Joined: Feb 01, 2012 12:04 pm
Full Name: Mario
Contact:

[MERGED] : Changing time window for multiple jobs

Post by marius roma »

I have many jobs with time windows so, for example, they cannot run from Monday to Friday from 8:00 AM to 8:00 PM.
They can run instead on Saturday and Sunday.
This is a standard time window and is ok.
Given that fow a given week a week day (let's say Tuesday) is bank holiday, is there a way to change the time window for all my jobs so that jobs can run on Tuesday for the next week and change again the time window for all my hob when the bank holiday is over to re-establish the standard time window?
Regards
marius
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Editing Backup Windows

Post by veremin »

You can modify the script provided above in order for it to change the said settings for multiple jobs, instead for single one. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests