PowerShell script exchange
Post Reply
burnsrbeef
Novice
Posts: 3
Liked: 1 time
Joined: Jan 09, 2014 3:28 pm
Full Name: James Hobai
Contact:

Set tape job to run after previous tape job completes

Post by burnsrbeef »

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.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

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.
burnsrbeef
Novice
Posts: 3
Liked: 1 time
Joined: Jan 09, 2014 3:28 pm
Full Name: James Hobai
Contact:

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

Post by burnsrbeef »

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".
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

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.
burnsrbeef
Novice
Posts: 3
Liked: 1 time
Joined: Jan 09, 2014 3:28 pm
Full Name: James Hobai
Contact:

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

Post by burnsrbeef » 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..."
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin »

Thank you for sharing the resulting code; appreciated. Should other help be needed, don't hesitate to ask. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests