Set tape job to run after previous tape job completes

PowerShell script exchange

Set tape job to run after previous tape job completes

Veeam Logoby burnsrbeef » Thu Jun 16, 2016 4:11 pm

I am trying to schedule my tape jobs to run one after the other. From my research I have developed two methods, both of which run into snags.

Method 1:

Code: Select all
Get-VBRTapeJob -Name $backup'_TAPE' -EA SilentlyContinue | Set-VBRJobSchedule -After -AfterJob $lastjob


After running this, the "Next Run" column when viewing all the tape jobs does change to the desired value (the job before it). However when editing the job schedule in the GUI, the radio button for "Daily at this time:" is still checked, not "After this job:" (despite the value for "After this job:" also being the desired value). Not sure if this is a bug or not, but despite what the "Next Run" column says, the jobs will still kick off with whatever value is in the daily schedule.

I have also attempted the following:

Code: Select all
New-VBRBackupToTapeScheduleOptions -Type Afterjob -Job $lastjob


However it appears that
Code: Select all
-Job
must be a VBRJob and cannot be a tape job.

Any thoughts would be appreciated.
burnsrbeef
Novice
 
Posts: 3
Liked: 1 time
Joined: Thu Jan 09, 2014 3:28 pm
Full Name: James Hobai

Re: Set tape job to run after previous tape job completes

Veeam Logoby v.Eremin » Mon Jun 20, 2016 6:13 pm

Can you try this script and see whether it works for you:

Code: Select all
asnp VeeamPSSnapin
$Tape1 = Get-VBRTapeJob -name "Name of first Job"
$Tape2 = Get-VBRTapeJob -name "Name of second Job"

$Schedule = New-VBRBackupToTapeScheduleOptions -Type AfterJob -Job $Tape1 -Enabled

Set-VBRBackupToTapeJob -Job $Tape2 -ScheduleOptions $Schedule


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

Re: Set tape job to run after previous tape job completes

Veeam Logoby burnsrbeef » Mon Jun 20, 2016 6:54 pm

Same error as when I tried using that cmdlet without the "-Enabled" on the end.

Code: Select all
New-VBRBackupToTapeScheduleOptions : Cannot bind parameter 'Job'. Cannot convert the "backup_TAPE" value of type "System.String" to type "Veeam.Backup.PowerShell.Infos.VBRJob".
burnsrbeef
Novice
 
Posts: 3
Liked: 1 time
Joined: Thu Jan 09, 2014 3:28 pm
Full Name: James Hobai

Re: Set tape job to run after previous tape job completes

Veeam Logoby v.Eremin » Tue Jun 21, 2016 10:32 am

As the error suggests, your variable (backup_Tape) doesn't seem to contain valid data. Instead of a tape job object it has string one assigned to it.

So, something must be wrong with a way you declare it.

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

Re: Set tape job to run after previous tape job completes

Veeam Logoby burnsrbeef » Mon Jun 27, 2016 2:39 pm 1 person likes this post

Thanks, that was indeed the problem. Here is the complete version which did what I expected.

Code: Select all
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

## Have a CSV (or text file) with Backup Jobs listed. The script assumes your Jobs follow the naming convention
## of Backup Job is "VM_name" and Tape Jobs are "VM_name_TAPE". You may have to tweak this as needed.
foreach ($backup in Get-Content "C:\util\scripts\weekly2_tape.csv"){
        ## Enter first VM in file here, this will be the job you schedule with a time to kick off the chain.
        if ($backup -eq "VM_name"){
        Set-Variable -Name "lastjob" -Value $backup'_TAPE'
        Write-Host "First Job is" $lastjob
    }
        else{
        Set-Variable -Name "backup" -Value $backup'_TAPE'
        Write-Host "Configuring Job " -NoNewline; Write-Host $backup -NoNewline; Write-Host " to run after" $lastjob
        $lasttape = Get-VBRTapeJob -Name $lastjob
        $backuptape = Get-VBRTapeJob -Name $backup
        $schedule = New-VBRBackupToTapeScheduleOptions -Type AfterJob -Job $lasttape -Enabled
        Set-VBRBackupToTapeJob -Job $backuptape -ScheduleOptions $schedule
            if($? -eq 'True'){
            Set-Variable -Name "lastjob" -Value $backup
            Write-Host `n"Last job is now" $lastjob `n
            }
                else{
                Write-Host `n $backup'_TAPE' -NoNewline; Write-Host " is not a valid Tape Backup Job Name" `n
                }
        }
}
Write-Host `n"Finished Scheduling Jobs..."
burnsrbeef
Novice
 
Posts: 3
Liked: 1 time
Joined: Thu Jan 09, 2014 3:28 pm
Full Name: James Hobai

Re: Set tape job to run after previous tape job completes

Veeam Logoby v.Eremin » Tue Jun 28, 2016 6:22 am

Thank you for sharing the resulting code; appreciated. Should other help be needed, don't hesitate to ask. Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 966 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: Google [Bot] and 9 guests