Using BEMCLI Powershell module with smarter error reporting
We're in the process of moving from BE2010 to BE2012, and with that I want to monitor the jobs better using theBEMCLI[1] module.
So far, so good, to a degree. Here's what I have:
$serverList = @("server01","server02","server03")
function List-BEJobs {
param(
$serverName
)
$s = New-PSSession -ComputerName $serverName
Invoke-Command -session $s {
Import-Module "C:\Program Files\Symantec\Backup Exec\Modules\BEMCLI\BEMCLI"
Get-BEJob | Get-BEJobHistory -FromLastJobRun -JobType Backup -JobStatus Scheduled
}
Remove-PSSession -session $s
}
$output = ''
foreach ($server in $serverList) {
$BEServer = List-BEJobs -serverName $server | select-object -property *
$BEServer
$output += "Server Name: ",$BEServer.BackupExecServerName,"`n" -join ''
$output += "Job Name: ",$BEServer.JobName,"`n" -join ''
$output += "Job Status: ",$BEServer.JobStatus," - ",$BEServer.SubStatus,"`n" -join ''
$output += "Time: ",$BEServer.StartTime,"-",$BEServer.EndTime," (",$BEServer.ElapsedTime,")`n" -join ''
$output += "% Complete: ",$BEServer.PercentComplete,"`n`n" -join ''
}
This results in the following for a failed job:
Server Name: Server01 Job Name: Daily Backups-XYZ_Policy Job Status: Canceled - Time: 1/1/2013 10:00:02 PM-1/1/2013 10:26:18 PM (00:26:16) % Complete: -1
Basically, althrough Get-BEJob provides SubStatus, Get-BEJobHistory does not, and this means I have very little to go on for why a job failed.
SubStatus is an enumerated list whose values can be found here: http://www.symantec.com/connect/blogs/get-bejob-substatus-and-other-properties[2] (about halfway down).
The properties of Get-JobHistory do not appear to include any error codes, etc. that would help be find this out.
Basically, I want to reduce the need to connect to a remote server in order to start investigating the failure, since I've got ~50 BE installations in two countries and need to streamline the process.
Any advice on this would be welcome!
Comments 5 Comments • Jump to latest comment
Hi GregWWebster,
I saw your post both here and on Reddit -- the answer on Reddit suggesting that you use Get-BEJobLog is the best approach available right now to retrieve a readable error description. However, as noted in that post, job logs can be verbose and are automatically removed from your backup server periodically. For recently run jobs, they should always be available and have more low-level job runtime details than the history.
However, the JobHistory does have two fields that you may find useful: ErrorCode and ErrorCategory. They are not shown in your console output by default, but they're part of all JobHistory objects. Try this:
Get-BEJobHistory | Format-List *
"Format-List *" shows all properties, not just the default visible set.
I've looked for a way to retrieve the readable text description that maps to the ErrorCode/ErrorCategory but have not come up with a solution. Right now, the numeric codes are the best info I can point you to.
Thanks for getting back to me.
When I run the code, the result in $BEServer contains the following (anonymized):
function Get-JobIdInfo { param( $serverName, $JobId ) "Server: $serverName" "ID: $JobId" $s = New-PSSession -ComputerName $serverName Invoke-Command -session $s { Import-Module "C:\Program Files\Symantec\Backup Exec\Modules\BEMCLI\BEMCLI" Get-BEJobHistory -Id $JobId } Remove-PSSession -session $s }When I run that, using ID, JobId or RunSpaceId, I get the following error:
Cannot validate argument on parameter 'Id'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again. + CategoryInfo : InvalidData: (:) [Get-BEJobHistory], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,BackupExec.Management.CLI.Commands.GetBEJobHistoryCommandWhat you're dealing with here is a nuance of Invoke-Command with PowerShell sessions. I cooked up the following test to illustrate:
function Test-Scope { param( $parameter ) # Show $parameter via inherited scope, and passed as an argument. Invoke-Command { param($parameterArg) "parameter : $parameter" "parameterArg : $parameterArg" } -ArgumentList $parameter # Try again, but in another session: $s = New-PSSession Invoke-Command { param($parameterArg) "Session parameter : $parameter" "Session parameterArg : $parameterArg" } -ArgumentList $parameter -Session $s } PS C:\Windows\system32> Test-Scope "hi" parameter : hi parameterArg : hi Session parameter : Session parameterArg : hiThe Session parameter case shows what's going on -- since you're invoking the command on a separate session, the $jobId needs to passed via the -ArgumentList parameter of Invoke-Command. You'll also want to add a param() block inside the scriptblock:
function Get-JobIdInfo { param( $serverName, $JobId ) "Server: $serverName" "ID: $JobId" $s = New-PSSession -ComputerName $serverName Invoke-Command -session $s { param($JobId) Import-Module "C:\Program Files\Symantec\Backup Exec\Modules\BEMCLI\BEMCLI" Get-BEJobHistory -Id $JobId } -ArgumentList $JobId Remove-PSSession -session $s }
I think that'll do it.
Thank you! Here's the result of that, with all properties:
I had thought initially that I was not getting the ErrorCode and ErrorCategory, but it just appears that the data in them is not useful...maybe? Do you have a list of what these values should correspond to?
I'm starting to deal with Powershell just for BECli and I find this post very interesting because I want to do a report like that. I'll keep my subscription to this post for further updates.
A second of your life, ruined for life.
Would you like to reply?
Login or Register to post your comment.