Video Screencast Help
Symantec to Separate Into Two Focused, Industry-Leading Technology Companies. Learn more.

Use BEMCLI to chain jobs

Created: 02 Apr 2012 • Updated: 14 Jun 2012 | 20 comments
Language Translations
pkh's picture
+6 6 Votes
Login to vote
BE 2012 is server-centric and in most cases, you end up with at least one job per server.  This means that it is more a chore to schedule your jobs.
 
You can start all the jobs on or about the same time, but you would not be sure which job runs first and which runs next.  This has serious implications when you want to overwrite a tape and then append to it.  Setting job priority will only be of use if you have 5 or less jobs.
 
To make sure that the jobs run in the sequence that you want, you can schedule the next job to start some time after the preceding job ends.  This means leaving a gap between jobs.  However, if your backup window is tight, this method is not desirable.
 
The other way is to use BEMCLI to chain your jobs.  Before you can use BEMCLI, you need to setup your Powershell environment so that it can run BEMCLI and scripts.  See my article on how to do so.
 
 

Get The Names Of Your Jobs

 
From the Powershell console, issue the command
 
Get-BEJob
 
This will return the list of jobs, e.g.
 
Name                        : P1-full
JobType                     : Backup
TaskType                   : Full
TaskName                 : full
IsActive                     : False
Status                       : Scheduled
SubStatus                 : Ok
SelectionSummary     : C: (Partial)
Storage                     : All Devices (Server1)
Schedule                   : Day 1 every 1 month(s) at 11:00 AM effective on 3/7/2012
IsBackupDefinitionJob : True
 
'''''
 
Name                        : P1-incr
JobType                    : Backup
TaskType                  : Full
TaskName                 : full
IsActive                     : False
Status                       : Scheduled
SubStatus                 : Ok
SelectionSummary     : C: (Partial)
Storage                     : All Devices (Server1)
Schedule                   : Day 1 every 1 month(s) at 11:00 AM effective on 3/7/2012
IsBackupDefinitionJob : True
 
From the result, decide what jobs you want to chain, filter for them and get their names.  For example,
 
Get-BEJob | Where-Object {($_.JobType -eq "Backup") -and ($_.Status -eq "Scheduled")} | Select-Object name > c:\jobs.txt
 
The above command will get the list of jobs, select only scheduled backup jobs and write their names to the file, jobs.txt
 

Use The Post-Command To Start The Next Job.

 
Once you have decided on your sequence of jobs.  Put all the jobs on hold except for the first job, then edit each of the jobs in turn to put in the post-command to start the next job.  For example, in Job1, put the post-command to start Job2 as follows
 
c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe Start-BEJob -In '"Job2"' -Confirm:$False
 
Note that the job name is surrounded by double-quotes ("), then single-quotes (')
 
Do that for your each of the jobs in turn.
 

Use The Windows Scheduler To Run A List of Jobs.

 
1) Put all your jobs on hold.
 
2) Create a Powershell script which has commands like these
 
Start-BEJob -In "Job1" -Confirm:$False | Wait-BEJob
Start-BEJob -In "Job2" -Confirm:$False | Wait-BEJob
...
Start-BEJob -In "Job10" -Confirm:$False | Wait-BEJob
 
These commands will start a BE job, wait for it to end and then go on to the next command which is to start the next BE job and wait.
 
A Powershell script is just a text file with a .ps1 file extension, e.g. jobs.ps1
 
3) Use The Windows Scheduler To Schedule the Powershell Script.
 
You then use the Windows Scheduler to issue this command.
 
c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe 'c:\jobs.ps1' | Format-Table -Auto -Wrap > c:\job-results.txt
 
Change the script name and location and the result file name and location to suit your needs.
 
The result file will give you a nice report of the job history of all the jobs run, e.g.
 
 
Name                                 JobStatus      JobType   StartTime                    EndTime              
----                                      ---------           -------         ---------                         -------              
Job1                                   Succeeded    Backup     3/7/2012 1:06:08 AM   3/7/2012 1:37:52 AM  
Job2                                   Succeeded    Backup     3/7/2012 1:38:11 AM   3/7/2012 2:08:50 AM  
....
Job10                                 Succeeded    Backup      3/7/2012 5:28:11 AM   3/7/2012 7:48:50 AM  
 
 
Another way to run it series of jobs is given here
 
 
I have also developed a script for the above method of chaining jobs.
 
https://www-secure.symantec.com/connect/downloads/script-chaining-jobs-be-2012
 

Use The First Job To Start The Rest Of The Jobs.

 
The last way is a combination of the first two methods.  This way will save you the trouble of having to use the Windows scheduler and you do not have to put post-commands in every job.
 
1) Put all jobs on hold except for the first one.
 
2) Create the Powershell script to start the second job onwards.  The script should have commands like these
 
Start-BEJob -In "Job2" -Confirm:$False | Wait-BEJob
Start-BEJob -In "Job3" -Confirm:$False | Wait-BEJob
...
Start-BEJob -In "Job10" -Confirm:$False | Wait-BEJob
 
3) Put this as the post-command in Job1.
 
c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe 'c:\jobs.ps1' | Format-Table -Auto -Wrap > c:\job-results.txt
 
As before, change the script name and location and the result file name and location to suit your needs.
 
The result file will give you a nice report of the job history of all the jobs run, e.g.
 
 
Name      JobStatus  JobType   StartTime                   EndTime              
----           ---------       -------         ---------                        -------              
 
Job2       Succeeded Backup    3/7/2012 1:38:11 AM   3/7/2012 2:08:50 AM  
Job3       Succeeded Backup    3/7/2012 2:08:51 AM   3/7/2012 4:37:52 AM 
....
Job10     Succeeded Backup    3/7/2012 5:28:11 AM   3/7/2012 7:48:50 AM  
 
If you are using a script to start your jobs, you can easily start two or more jobs at once.  For example
 
Start-BEJob -In "Job1" -Confirm:$False | Wait-BEJob
Start-BEJob -In "Job2" -Confirm:$False 
Start-BEJob -In "Job3" -Confirm:$False | Wait-BEJob
Start-BEJob -In "Job4" -Confirm:$False | Wait-BEJob
...
Start-BEJob -In "Job10" -Confirm:$False | Wait-BEJob
 
This script will start Job2 and then immediately start Job3 because it does not wait for Job2 to finish.  This also means that there would be no job history for Job2 in the job results file.
 
If you are using a script, then you are not restricted to just starting jobs.  Before starting jobs, you can insert commands to do other tasks, like import a tape or export a tape, etc.
 
 
P.S. If you are using BE 2010 and below, you can use BEMCMD to chain your jobs.  See my blog
 
https://www-secure.symantec.com/connect/blogs/use-bemcmd-start-jobs
 
 

Comments 20 CommentsJump to latest comment

rafd123's picture

Recommendation: instead of -Confirm:$false on each command, use $ConfirmPreference="None"

http://nukeitmike.com/blog/2010/03/04/powershell-c...

0
Login to vote
pkh's picture

Why do you recommend $ConfirmPreference="None"? Is it better?

0
Login to vote
rafd123's picture

It's just less repetitive. Once you put it at the top of the script, you don't have to add the -Confirm switch to every cmdlet call.

0
Login to vote
Siegfried's picture

Quotes doesn't works for me:

Start-BEJob -In '"Job1"'

0
Login to vote
pkh's picture

Post the full command and how do you use it, whether in a Powershell console, as a script or as a pre-/post -command, as a discussion in the forum section and I will take it from there.

0
Login to vote
pkh's picture

An alternative to creating the script described in the article above is to do the following:-

1) Suppose you have a file called c:\jobs.txt with the following contents

Job1 

Job2  
....
Job10      
 
2) Then you can schedule this Powershell command to start your jobs.
 
c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe "Get-Content c\jobs.txt | % {Get-BEjob -name $_ | Start_BEJob $confirm:$false | Wait-BEJob} | Format-Table -Auto -Wrap > c:\job-results.txt"
0
Login to vote
abelej's picture

pkh,

I really like your solution on chaining. 

I have a similar need but would also like to introduce a 10 minute delay in between 2 jobs.

For example job1 runs, then would like 10 minute delay for cleanup actions to complete, then run job2 in that order.

Any suggestions?  Your command sequentially starts next chained job within seconds of the first completing.

jonnsideways's picture

Once you chain a job using the cmd line tools does it show this fact anywhere in the BE GUI?

cheers

John

0
Login to vote
pkh's picture

No.

0
Login to vote
What the's picture

Oh dear... This is terrible. What was Symantec thinking? Definately going to downgrade to 2010 R3.

+1
Login to vote
jonnsideways's picture

Good lick with that. as if you go up to 2012, it changes the schema on the database, and down grading is difficult, I didnt investigate the downgrade a lot, but tried to reinstall on a differnet Database, and the result was the same I kept getitng a "Schem has been modifed Error" ;0(

A week on I am liking the new product, though it is confusing and makes normal tasks much harder than in the past. Seems quicker though, and has lots more information on the front view.

0
Login to vote
Juve's picture

This version seems to be like a "Small Business" version for only 1 server

If you need to backup 20 servers you will get 20 jobs this is not acceptable

0
Login to vote
Andre Ruas's picture
I´m a BE TSA, got a quiestion, please answer:
 
NOTE: Using an Autoloader
After Each job finishes it rewinds the tape and places the tape again to the same or diferent slot as before.
The next Job starts, it imports 1 Tape and Appends to it.
This usually take up to 15 min everytime the next job runs, depends
 
BEFORE when I could select all my SQL Instances in the SAME JOB it didn´t ejected the tape each time it swiched from one SQL instance to another and rewinded the tape and then appended to ti.
His jobs used finished in 5-7 hours.
Now it´s taking up to 12 hours to BACKUP The same SQL Instances on a 1 job per server way.
 
NOTE: You´ve stated that This script will start Job2 and then immediately start Job3 because it does not wait for Job2 to finish.  This also means that there would be no job history for Job2 in the job results file
 

Does it rewind the tape, eject it and append to it if the jobs are CHAINNED? or it continues using the same tape up to that point?

or is the same are individual jobs, between each job they lose about 15 min. everytime a new job starts?

 
 
CTM ICT's picture

Hi!

In my case the backup jobs habe the names:

Name                                                                                                                   
----                                                                                                                   
SCOM - Daily-Full                                                                                                      
CTMDomino - Daily-Full                                                                                                 
DOG02 - Daily-Full                                                                                                     
SAP_PRD - Daily-Full                                                                                                   
SAP_DEV - Monthly-Backup                                                                                               
WorkFlow - Daily-Full                                                                                                  
SAP_CONT - Daily-Full                                                                                                  
Exhange - Daily-Full                                                                                                   
 

as they extracted from the command

[ Get-BEJob | Where-Object {($_.JobType -eq "Backup") -and ($_.Status -eq "Scheduled")} | Select-Object name > c:\jobs.txt ]

I tried to schedule some jobs following your instructions but didn't work.

When I tried the command Start-BEJob -In '"WorkFlow - Daily-Full"' -Confirm:$False

direct in a Powershel, I got this result:

Start-BEJob : Cannot bind parameter 'InputObject'. Cannot convert value ""WorkFlow - Daily-Full"" to type "BackupExec.Management.CLI.BEJob". Error: "Cannot find any Job objects with the name "WorkFlow - Daily-Full"."
At line:1 char:16
+ Start-BEJob -In <<<<  '"WorkFlow - Daily-Full"' $ConfirmPreference="None"
    + CategoryInfo          : InvalidArgument: (:) [Start-BEJob], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,BackupExec.Management.CLI.Commands.StartBEJobCommand

Could you be so kind to give a hand please?

Thnak you

Vassilis

0
Login to vote
Tim Collins_'s picture

Try Start-BeJob -Name "NameofJob"

0
Login to vote
Tim Collins_'s picture

I'm having a problem with the methods described here. If you have a job on hold and you start the job, when the job is completed it is no longer on hold. If I'm chaining 20-30 jobs together there's a chance that a prior job in the chain could be run by the BE scheduler. 

I'm getting around this by changing the schedules to two years in the future and placing all jobs on hold at the end of the script. Is there a more elegant solution?

0
Login to vote
Abb3y's picture

Just wondering, how will you tweak this script where there are 2 or 3 storage devices. In other words, you want Job1, Job2, Job3 to start first using cartridge1, catridge2, catridge3. Other jobs (Job4, Job5... Job15) you want to put on hold.

I will appreciate your ideas.

BDO Taranaki IT's picture

LOL - you can go through this nightmare of a Job Chaining procedure using command line, OR use the simple GUI in the previous version of Backup Exec 2010. My choice is stick with the previous version and save myself hours of frustration. Maybe they can make BE2014 like BE2010???

0
Login to vote
Siegfried's picture

I'm testing BE2014 and it makes its job like 2010 (single job for multiple server to tape).

+1
Login to vote
jonnsideways's picture

Sounds good. As we migrated successfully to 2014, I had just left the Jobs alone, as I got so used to the new interface. I do like the way you can navigate around 2014 better, and that you can clear down notifications easier. Must say though for my regular server backups I bought a Dell Appassure device, so I can stop worrying about BE all together ;0)

+1
Login to vote