Use BEMCLI to chain jobs
Created: 02 Apr 2012 | Updated: 14 Jun 2012 | 17 comments
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
Article Filed Under:
Comments 17 Comments • Jump to latest comment
Recommendation: instead of -Confirm:$false on each command, use $ConfirmPreference="None"
http://nukeitmike.com/blog/2010/03/04/powershell-c...
Why do you recommend $ConfirmPreference="None"? Is it better?
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.
Quotes doesn't works for me:
Start-BEJob -In '"Job1"'
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.
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
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.
Once you chain a job using the cmd line tools does it show this fact anywhere in the BE GUI?
cheers
John
No.
Oh dear... This is terrible. What was Symantec thinking? Definately going to downgrade to 2010 R3.
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.
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
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?
Hi!
In my case the backup jobs habe the names:
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:
Could you be so kind to give a hand please?
Thnak you
Vassilis
Try Start-BeJob -Name "NameofJob"
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?
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.
Would you like to reply?
Login or Register to post your comment.