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

Using BEMCLI Powershell module with smarter error reporting

Created: 02 Jan 2013 • Updated: 03 Jan 2013 | 5 comments

 

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 CommentsJump to latest comment

BE_KirkFreiheit's picture

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.

GregWWebster's picture

Thanks for getting back to me. 

 

When I run the code, the result in $BEServer contains the following (anonymized):

 

PSComputerName       : server01
RunspaceId           : e22068d9-3c9d-40af-afe1-e2d44698cc4d
PSShowComputerName   : True
Name                 : Daily Backups-XYZ_Policy
Id                   : 906aa413-7ed9-40ec-b5ca-d297545033c6
JobName              : Daily Backups-XYZ_Policy
JobStatus            : Canceled
StartTime            : 1/4/2013 10:00:03 PM
EndTime              : 1/4/2013 10:32:48 PM
ElapsedTime          : 00:32:45
TotalDataSizeBytes   : 0
JobRateMBPerMinute   : -1
DeduplicationRatio   : 0
JobType              : Backup
PercentComplete      : -1
StorageName          : 
BackupExecServerName : server01
Job                  : Daily Backups-XYZ_Policy
JobId                : 326ddcca-09e7-4565-bc4c-9083731cb0ac
AgentServer          : server01.mydomain.ca
AgentServerId        : 5a9faf22-d7ee-4f1f-94bf-bf17802a7a5f
JobLogFilePath       : C:\Program Files\Symantec\Backup Exec\Data\BEX_server01_00496.xml
ErrorCode            : 0
ErrorCategory        : 1
 
I created the following function:
 
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.GetBEJobHistoryCommand
 
However, I've verified (by outputting the value to screen) that it's definitely not "null or empty" when inside that function.
 
All help is appreciated! Our move across the board to 2012 is depending on this. Thanks!

 

BE_KirkFreiheit's picture

What 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 : hi

The 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.

GregWWebster's picture

 

Thank you! Here's the result of that, with all properties:

Name                 : Daily Backups-XYZ_Policy
Id                   : 906aa413-7ed9-40ec-b5ca-d297545033c6
JobName              : Daily Backups-XYZ_Policy
JobStatus            : Canceled
StartTime            : 1/4/2013 10:00:03 PM
EndTime              : 1/4/2013 10:32:48 PM
ElapsedTime          : 00:32:45
TotalDataSizeBytes   : 0
JobRateMBPerMinute   : -1
DeduplicationRatio   : 0
JobType              : Backup
PercentComplete      : -1
StorageName          :
BackupExecServerName : server01
Job                  : Daily Backups-XYZ_Policy
JobId                : 326ddcca-09e7-4565-bc4c-9083731cb0ac
AgentServer          : server01.mydomain.ca
AgentServerId        : 5a9faf22-d7ee-4f1f-94bf-bf17802a7a5f
JobLogFilePath       : C:\Program Files\Symantec\Backup Exec\Data\BEX_server01_00496.xml
ErrorCode            : 0
ErrorCategory        : 1
PSComputerName       : server01
RunspaceId           : d4d427b8-7b25-4432-b898-290ff583038c
PSShowComputerName   : True

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?

 

King_Julien's picture

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.