Knowledge Base Article

Use BEMCLI to chain jobs

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
 
 
Published 13 years ago
Version 1.0

Was this article helpful?

21 Comments

  • Can you tell me how to list the server name the job is attached to as well? sometimes the job name doesn't indicate this. I can see a field called "Server" when building a custom report through the gui report builder but I don't see this field in the BEMCLI under get-jobhistory. 

     

    Thanks :)