PowerShell script exchange
Post Reply
cffit
Veteran
Posts: 338
Liked: 35 times
Joined: Jan 20, 2012 2:36 pm
Full Name: Christensen Farms
Contact:

Scheduling Backups with Task Manager and PowerShell

Post by cffit »

I am attempting to setup a backup job in the VEEAM software and then on the weekend have the job run off a powershell scripts run by a scheduled task.

I do this by setting up a job in VEEAM and checking it to run Monday through Friday at 8PM but NOT Saturday or Sunday. I set the "Create synthetic full backups periodically" and check Saturday for this option. However, as mentioned already, I do NOT check for the job to run on Saturday in the schedule part of the job.

Then I setup my powershell script and scheduled task to kick the job off on Saturday and schedule the task to run at 2AM. It seems like VEEAM still runs the job on Saturday at 8PM even though Saturday is NOT checked on the schedule. So my question is this. If Saturday is NOT checked on the schedule part of the job, but it is specified as the day for the synthetic job to run, will it still run at 8PM on Saturday?
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by veremin »

If Saturday is NOT checked on the schedule part of the job, but it is specified as the day for the synthetic job to run, will it still run at 8PM on Saturday?
Correct.
cffit
Veteran
Posts: 338
Liked: 35 times
Joined: Jan 20, 2012 2:36 pm
Full Name: Christensen Farms
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by cffit »

Ok. So what I am trying to accomplish is having a different weekend schedule than weekday. How can I use the method of PowerShell and scheduled tasks to schedule my weekend full backups to run at an earlier time than the weekdays? I assume I need to have Saturday specified at the day for my synthetic fulls to run, but I don't want the VEEAM schedule to run them, I want my scheduled task to run them.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by veremin »

Firstly, you need to disable both active and synthetic full backups. Secondly, schedule synthetic full on demand script (the second one) via Task Scheduler to take place at whatever time you want to. Thanks.
cffit
Veteran
Posts: 338
Liked: 35 times
Joined: Jan 20, 2012 2:36 pm
Full Name: Christensen Farms
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by cffit »

How do I tell the script to run the synthetic or full backups? I have seen the scripts on here that call the backup job, but that just calls the job in the GUI and doesn't specify what type of backup to run.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by veremin »

The first script disables both active and synthetic fulls for a given job.

The second script thread does the following:

- Get a job with the specified name
- Enables synthetic full for it
- Set synthetic full to run on the current day
- Starts the job

Being scheduled via Task Scheduler, the second script will give you what you're after.

Thanks.
cffit
Veteran
Posts: 338
Liked: 35 times
Joined: Jan 20, 2012 2:36 pm
Full Name: Christensen Farms
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by cffit »

Can you post the script here again? The script I found on here was just simply calling the job to run, none of the rest of what you mention. Thanks!
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by tsightler »

I think it might be easier to just have a post-job script that runs after each job run and, if it's Friday, changes the next scheduled run time to the weekend schedule, and if it's Sunday, changes it back to the weekday schedule. Or at least just use Windows task scheduler to toggle the scheduled run time back and forth as that script would be super easy, probably one-liner. To me that sounds easier than trying to trigger job runs manually all the time, but perhaps I missed the full use case.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by veremin »

I've provided the hyper-link in my second answer. But I can post the scripts here, as well:

First:

Code: Select all

Add-PSSnapin VeeamPSSnapin
$JobOptions = Get-Vbrjob -name "Job name" | Get-VBRJobOptions
$JobOptions.BackupTargetOptions.TransformFullToSyntethic = $False
$JobOptions.BackupStorageOptions.EnableFullBackup = $False
$Job.SetOptions($JobOptions)
Second:

Code: Select all

Add-PSSnapin VeeamPSSnapin
$Job = Get-Vbrjob -name "Name of your job"
$OptionsToSet = $Job | Get-VBRJobOptions
$OptionsToSet.BackupTargetOptions.TransformFullToSyntethic = $True
$OptionsToSet.BackupTargetOptions.TransformToSyntethicDays = (Get-Date).DayOfWeek
$Job.SetOptions($OptionsToSet)
Start-VBRJob -Job $Job
$OptionsToSet.BackupTargetOptions.TransformFullToSyntethic = $False
$Job.SetOptions($OptionsToSet)
Thanks.
cffit
Veteran
Posts: 338
Liked: 35 times
Joined: Jan 20, 2012 2:36 pm
Full Name: Christensen Farms
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by cffit »

tsightler wrote:I think it might be easier to just have a post-job script that runs after each job run and, if it's Friday, changes the next scheduled run time to the weekend schedule, and if it's Sunday, changes it back to the weekday schedule. Or at least just use Windows task scheduler to toggle the scheduled run time back and forth as that script would be super easy, probably one-liner. To me that sounds easier than trying to trigger job runs manually all the time, but perhaps I missed the full use case.
I'm not good with scripting. Would you or someone be able to provide the one liner for me? I really do just need to adjust the schedule for Saturdays only. So if I could just have my schedule in VEEAM set to do incrementals M-F and then fulls on Saturday, then have a script that would run Saturday at 12:01AM that changed the scheduled time to 2AM, and then a script that would run sometime on Sunday that would change the schedule time back to what I want for M-F that would be great too.
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by tsightler » 1 person likes this post

Something like this:

Code: Select all

Set-VBRJobSchedule -Job "<Job_Name>" -At "20:00" -Daily
That configures the job to run at 8PM each day. You can also add the "-Days" parameter to get the job to run only on specific days. So, for example, you could create two tasks in task scheduler, one that runs on 1:55AM on Saturday and changes the job to run at 2AM. And then another than runs later that switches it back to the "normal" 8PM schedule. So, for example:

Set job to run Saturday at 2AM:

Code: Select all

Set-VBRJobSchedule -Job "<Job_Name>" -At "02:00" -Daily -DailyKind SelectedDays -Days Saturday
Set job to run Mon-Fri at 8PM:

Code: Select all

Set-VBRJobSchedule -Job "<Job_Name>" -At "20:00" -Daily -DailyKind Weekdays
cffit
Veteran
Posts: 338
Liked: 35 times
Joined: Jan 20, 2012 2:36 pm
Full Name: Christensen Farms
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by cffit »

Thank you for posting these Tom. I will give them a try and if they work I will post to another thread on here where others are trying to do the same thing. So this will just change the time the job runs? And the options of being active full, synthetic full or incremental will go off of what is in the VEEAM job setup already in the software correct?
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by tsightler »

Right, this is only changing the schedule. It's effectively the same as using the GUI to go to the schedule page in the job wizard and changing the scheduling options there. It will not impact other job settings such a active/synthetic/incremental.
foggy
Veeam Software
Posts: 21139
Liked: 2141 times
Joined: Jul 11, 2011 10:22 am
Full Name: Alexander Fogelson
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by foggy »

cffit wrote:If Saturday is NOT checked on the schedule part of the job, but it is specified as the day for the synthetic job to run, will it still run at 8PM on Saturday?
Just to clarify: it will run, however it will not perform synthetic for the second time a day, it will be a regular incremental run.
cffit
Veteran
Posts: 338
Liked: 35 times
Joined: Jan 20, 2012 2:36 pm
Full Name: Christensen Farms
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by cffit »

tsightler wrote:Right, this is only changing the schedule. It's effectively the same as using the GUI to go to the schedule page in the job wizard and changing the scheduling options there. It will not impact other job settings such a active/synthetic/incremental.
Thanks Tom, this is working just as I wanted it to. I'm still frustrated that this capability isn't in the GUI...

Is the backup to tape syntax the same? For instance if I want to reschedule the tape backup job for the weekend to run at a different time than weekdays?

I see I should probably use "Set-VBRBackupToTapeJob" but I don't know the rest of the syntax I'd use.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by veremin »

Leverage something like this:

Code: Select all

asnp VeeamPSSnapin
$Job = Get-VBRTapejob -name "Name of your tape job"
$Daily = New-VBRDailyOptions -Type Everyday -Period "New Period" #say "11:00"
$NewSchedule  = New-VBRBackupToTapeScheduleOptions -Type Daily -DailyOptions $Daily -Enabled
Set-VBRBackupToTapeJob -Job $Job -ScheduleOptions $NewSchedule
Thanks.
cffit
Veteran
Posts: 338
Liked: 35 times
Joined: Jan 20, 2012 2:36 pm
Full Name: Christensen Farms
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by cffit »

Thanks Vladimir. Is there a one-liner this could be cut down to and also specified to only set the schedule to Sunday?
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by veremin » 1 person likes this post

It can be converted into a one-liner, though, into long one:

Code: Select all

Set-VBRBackupToTapeJob -Job (Get-VBRTapeJob -Name "Name of your job") -ScheduleOptions (New-VBRBackupToTapeScheduleOptions -Type Daily -Enabled -DailyOptions (New-VBRDailyOptions -DayOfWeek Saturday -Period "New period"))
Thanks.
cffit
Veteran
Posts: 338
Liked: 35 times
Joined: Jan 20, 2012 2:36 pm
Full Name: Christensen Farms
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by cffit »

Thanks Tom and Vladimir. This is what I needed and I am going to write up what I did to explain to others how this worked for me. I am still adamant that it should be an option in the GUI :)
Darius-HL
Lurker
Posts: 1
Liked: never
Joined: Jul 24, 2017 1:46 am
Full Name: Darius L
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by Darius-HL »

I could not agree more with the original poster! For an enterprise grade product, It's a shame to not have a more dependable, GUI-based scheduling approach which helps to ensure that a job runs even if a previous job were to run over - without the pitfalls of chained jobs.
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Scheduling Backups with Task Manager and PowerShell

Post by veremin »

Hi, Darius,

Could elaborate on the issue experienced? May be there is something we can propose to you.

Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests