Enable a Disabled Backup Job

PowerShell script exchange

Enable a Disabled Backup Job

Veeam Logoby mafiasilk » Tue Jan 28, 2014 3:20 pm

Hi Guys,
Im trying to automate SRM, and need to enable a disabled veeam job after the SRM job becomes live.

Can this be done with powershell?
The job name can remain static for this example call it 'SRMBackup'
mafiasilk
Influencer
 
Posts: 13
Liked: never
Joined: Thu Nov 28, 2013 10:40 am
Full Name: Asif Malik

Re: Enable a Disabled Backup Job

Veeam Logoby v.Eremin » Tue Jan 28, 2014 3:30 pm

You should use the following script:

Code: Select all
$Job = Get-VBRJob -name "Name of your Job"
$Job.EnableScheduler()

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Enable a Disabled Backup Job

Veeam Logoby mafiasilk » Tue Jan 28, 2014 4:36 pm

Thanks for the speedy response!
mafiasilk
Influencer
 
Posts: 13
Liked: never
Joined: Thu Nov 28, 2013 10:40 am
Full Name: Asif Malik

Re: Enable a Disabled Backup Job

Veeam Logoby tdewin » Fri Feb 07, 2014 4:59 pm

If you want a one liner
Code: Select all
Get-VBRjob -name "Name of your Job" | Disable-VBRJob


or to disable all jobs
Code: Select all
Get-VBRjob | ? { $_.JobType -eq "Backup" } |  Disable-VBRJob
tdewin
Veeam Software
 
Posts: 1043
Liked: 361 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin

Re: Enable a Disabled Backup Job

Veeam Logoby b.vanhaastrecht » Fri Feb 28, 2014 8:39 am

Hi, I would like to add some errorhandling on the disable-enable process. What posible errors may occour?

Code: Select all
Disable-VBRJob -Job "Jobname" -ErrorAction SilentlyContinue
If(!$?) {
     #Something went wrong
  }else{
     #Succes
  }


Or is there an other/better method to check if the job has been disabled/enabled?
========================================
Veeam ProPartner and Cloud Connect Provider
b.vanhaastrecht
Service Provider
 
Posts: 335
Liked: 65 times
Joined: Mon Aug 26, 2013 7:46 am
Location: The Netherlands
Full Name: Bastiaan van Haastrecht

Re: Enable a Disabled Backup Job

Veeam Logoby v.Eremin » Fri Feb 28, 2014 8:45 am

What posible errors may occour?

I can't think of any issues that prevent you from disabling job.

Or is there an other/better method to check if the job has been disabled/enabled?

You can check whether or not given job is disabled via the following script:

Code: Select all
$Job = Get-VBRJob -name "Name of your Backup Job"
$Job.CanRunByScheduler() #True - enabled, #False - disabled


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Enable a Disabled Backup Job

Veeam Logoby nefes » Fri Feb 28, 2014 9:14 am

If you want to handle any error, you can log $_.Error in "Something went wrong" section to troubleshoot problems.
For example, it will catch the case when you don't have job with name "Jobname"
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Enable a Disabled Backup Job

Veeam Logoby CaptainFred » Thu Mar 20, 2014 1:12 pm

Is there a way to have the script disable the job if it's enabled and enable the job if it's disabled? Would save having loads of scripts and scheduled tasks.

Also will this work for replication jobs as well as backup jobs?

Thanks
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Re: Enable a Disabled Backup Job

Veeam Logoby v.Eremin » Thu Mar 20, 2014 2:27 pm

As mentioned above, the CanRunByScheduler() parameter returns $False when either the job is disabled or the job schedule isn't enabled ("Run the automatically checkbox" is unticked). So, the required scripts should be as the following:

Code: Select all
(Get-VBRJob | where {$_.CanRunByScheduler() -eq $False}).EnableScheduler() #enable disabled jobs


Code: Select all
(Get-VBRJob | where {$_.CanRunByScheduler() -eq $True}).DisableScheduler() #disable enabled jobs


The given scripts work with all type of jobs, except for tape ones.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Enable a Disabled Backup Job

Veeam Logoby CaptainFred » Thu Mar 20, 2014 2:42 pm

Thanks, can they be tweaked to only do it for my jobs called "Backup Job - 1" and "Replication Job - 1" ?
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Re: Enable a Disabled Backup Job

Veeam Logoby v.Eremin » Thu Mar 20, 2014 2:46 pm

Try these scripts, then:

Code: Select all
$BackupJob = Get-VBRJob -name "Backup Job 1"
If ($BackupJob.CanRunByScheduler() -eq $False) {$BackupJob.EnableScheduler()}
Else {$BackupJob.DisableScheduler()}

Code: Select all
 
$ReplicaJob = Get-VBRJob -name "Replication Job 1"
If ($ReplicaJob.CanRunByScheduler() -eq $False) {$ReplicaJob.EnableScheduler()}
Else {$ReplicaJob.DisableScheduler()}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Enable a Disabled Backup Job

Veeam Logoby CaptainFred » Mon Mar 24, 2014 11:51 am

v.Eremin wrote:Try these scripts, then:

Code: Select all
$BackupJob = Get-VBRJob -name "Backup Job 1"
If ($BackupJob.CanRunByScheduler() -eq $False) {$BackupJob.EnableScheduler()}
Else {$BackupJob.DisableScheduler()}

Code: Select all
 
$ReplicaJob = Get-VBRJob -name "Replication Job 1"
If ($ReplicaJob.CanRunByScheduler() -eq $False) {$ReplicaJob.EnableScheduler()}
Else {$ReplicaJob.DisableScheduler()}


Thanks.


Getting these errors with this...

Code: Select all
Method invocation failed because [Veeam.Backup.Core.CBackupJob] doesn't contain
 a method named 'CanRunByScheduler'.
At C:\Scripts\EnableOrDisableMIJobs.ps1:4 char:33
+ If ($BackupJob.CanRunByScheduler <<<< () -eq $False) {$BackupJob.EnableSchedu
ler()}
    + CategoryInfo          : InvalidOperation: (CanRunByScheduler:String) [],
    RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

Method invocation failed because [Veeam.Backup.Core.CBackupJob] doesn't contain
 a method named 'CanRunByScheduler'.
At C:\Scripts\EnableOrDisableMIJobs.ps1:8 char:34
+ If ($ReplicaJob.CanRunByScheduler <<<< () -eq $False) {$ReplicaJob.EnableSche
duler()}
    + CategoryInfo          : InvalidOperation: (CanRunByScheduler:String) [],
    RuntimeException
    + FullyQualifiedErrorId : MethodNotFound


Is this meant to tick/untick the "Run the job automatically" box under schedule? Is it possible for this job disable or enable the job like the button on the toolbar does?

Thanks
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Re: Enable a Disabled Backup Job

Veeam Logoby v.Eremin » Mon Mar 24, 2014 12:03 pm

Getting these errors with this...

What product version you're currently at?

Is this meant to tick/untick the "Run the job automatically" box under schedule?

No, the abovementioned scripts should enable/disable the given jobs.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Enable a Disabled Backup Job

Veeam Logoby CaptainFred » Mon Mar 24, 2014 12:15 pm

7.0.0.771
CaptainFred
Enthusiast
 
Posts: 88
Liked: 2 times
Joined: Wed Jul 31, 2013 12:05 pm
Full Name: Si

Re: Enable a Disabled Backup Job

Veeam Logoby v.Eremin » Mon Mar 24, 2014 1:15 pm

May be the $BackupJob variable returns multiple entities, instead of one? Can you check whether the given variable is assigned properly? You can do it by inputting the variable in the pipeline:

Code: Select all
$BackupJob = Get-VBRJob -name "Backup Job 1"
$BackupJob


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests