Veritas-bu

[Veritas-bu] Re: bpdbjobs -all_columns

2007-07-24 15:39:17
Subject: [Veritas-bu] Re: bpdbjobs -all_columns
From: rmg <netbackup-forum AT backupcentral DOT com>
To: VERITAS-BU AT mailman.eng.auburn DOT edu
Date: Tue, 24 Jul 2007 09:18:53 -0700
Coincidentally, I wrote this just last week:


#!/usr/bin/perl

use Data&#58;&#58;Dumper;

# Each line of bpdbjobs output has a fairly long, complicated format
# described in the PDF&#58; NetBackup Commands for UNIX and Linux.

my $lineformat =
&nbsp; &#91;
&nbsp; &nbsp;'jobid', 'jobtype', 'state', 'status', 'class',
&nbsp; &nbsp;'schedule', 'client', 'server', 'started', 'elapsed',
&nbsp; &nbsp;'ended', 'stunit', 'try', 'operation', 'kbytes',
&nbsp; &nbsp;'files', 'pathlastwritten', 'percent', 'jobpid', 'owner',
&nbsp; &nbsp;'subtype', 'classtype', 'schedule_type', 'priority', 'group',
&nbsp; &nbsp;'masterserver', 'retentionunits', 'retentionperiod', 'compression',
&nbsp; &nbsp;'kbyteslastwritten', 'fileslastwritten',
&nbsp; &nbsp;'filelistcount'
&nbsp; &nbsp;=> &#91;
&nbsp; &nbsp; &nbsp; &nbsp;'files',
&nbsp; &nbsp; &nbsp; &#93;,
&nbsp; &nbsp;'trycount',
&nbsp; &nbsp;=> &#91;
&nbsp; &nbsp; &nbsp; &nbsp;'trypid', 'trystunit', 'tryserver', 'trystarted', 
'tryelapsed',
&nbsp; &nbsp; &nbsp; &nbsp;'tryended', 'trystatus', 'trystatusdescription',
&nbsp; &nbsp; &nbsp; &nbsp;'trystatuscount'
&nbsp; &nbsp; &nbsp; &nbsp;=> &#91;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'trystatuslines',
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#93;,
&nbsp; &nbsp; &nbsp; &nbsp;'trybyteswritten', 'tryfileswritten',
&nbsp; &nbsp; &nbsp; &#93;,
&nbsp; &nbsp;# Fields below taken from DWR's python script on
&nbsp; &nbsp;# Curtis Preston's backupcentral.com wiki.
&nbsp; &nbsp;'parentjob', 'kbpersec', 'copy', 'robot', 'vault',
&nbsp; &nbsp;'profile', 'session', 'ejecttapes', 'srcstunit', 'srcserver',
&nbsp; &nbsp;'srcmedia', 'dstmedia', 'stream', 'suspendable', 'resumable',
&nbsp; &nbsp;'restartable', 'datamovement', 'frozenimage', 'backupid', 
'killable',
&nbsp; &nbsp;'controllinghost',
&nbsp; &nbsp;# Plus one unaccounted for.
&nbsp; &nbsp;'unknown',
&nbsp; &#93;;

my %valuenames =
&nbsp; &#40;
&nbsp; &nbsp;'jobtype'
&nbsp; &nbsp;=> &#91;
&nbsp; &nbsp; &nbsp; &nbsp;'backup', 'archive', 'restore', 'verify', 
'duplication',
&nbsp; &nbsp; &nbsp; &nbsp;'import', 'dbbackup', 'vault', 'label', 'erase',
&nbsp; &nbsp; &nbsp; &nbsp;'tpreq', 'tpclean', 'tpformat', 'vmphyinv', 'dqts',
&nbsp; &nbsp; &nbsp; &nbsp;'dbrecover', 'mcontents',
&nbsp; &nbsp; &nbsp; &#93;,
&nbsp; &nbsp;'schedule_type'
&nbsp; &nbsp;=> &#91;
&nbsp; &nbsp; &nbsp; &nbsp;'FULL', 'INCR', 'UBAK', 'UARC', 'CINC',
&nbsp; &nbsp; &nbsp; &#93;,
&nbsp; &nbsp;'state'
&nbsp; &nbsp;=> &#91;
&nbsp; &nbsp; &nbsp; &nbsp;'queued', 'active', 'waiting for retry', 'done',
&nbsp; &nbsp; &nbsp; &#93;,
&nbsp; &nbsp;'subtype'
&nbsp; &nbsp;=> &#91;
&nbsp; &nbsp; &nbsp; &nbsp;'immediate', 'scheduled', 'user-initiated',
&nbsp; &nbsp; &nbsp; &#93;,
&nbsp; &#41;;

sub parse_bpdbjobs &#123;
&nbsp; my &#40;$fields, $format, $repeat&#41; = @_;

&nbsp; unless &#40;ref $fields&#41; &#123;
&nbsp; &nbsp; chomp $fields;
&nbsp; &nbsp; # split on unescaped commas; perl has variable-length
&nbsp; &nbsp; # lookahead but not lookbehind in regexps, so we work
&nbsp; &nbsp; # with reversed strings, then un-reverse each field *and*
&nbsp; &nbsp; # return the entire list of fields to normal order.
&nbsp; &nbsp; $fields = &#91; reverse map &#123; scalar reverse &#125;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # comma, NOT followed 
by&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; &nbsp;a 
backslash,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; &nbsp;followed 
by any even number of backslashes,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; &nbsp;followed 
by a non-backslash or end-of-string.
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
split&#40;/,&#40;?!\\&#40;?&#58;\\\\&#41;*&#40;?&#58;&#91;^\\&#93;|$&#41;&#41;/,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
scalar reverse&#40;$fields&#41;&#41; &#93;;
&nbsp; &#125;

&nbsp; $format = $lineformat unless &#40;defined $format&#41;;
&nbsp; $repeat = 1 unless &#40;defined $repeat&#41;;

&nbsp; my @result;

&nbsp; for &#40;my $i = 0; $i < $repeat; $i++&#41; &#123;
&nbsp; &nbsp; my %item = &#40;&#41;;

&nbsp; &nbsp; my $prev_field;
&nbsp; &nbsp; foreach my $format_field &#40;@$format&#41; &#123;
&nbsp; &nbsp; &nbsp; if &#40;ref $format_field&#41; &#123;
&nbsp; &nbsp; &nbsp; &nbsp; # sublist; expect number of repetitions given by 
the previous field
&nbsp; &nbsp; &nbsp; &nbsp; my $sublist = parse_bpdbjobs&#40;$fields, 
$format_field, $prev_field&#41;;
&nbsp; &nbsp; &nbsp; &nbsp; # hack&#58; name the sublist by the first field in 
it
&nbsp; &nbsp; &nbsp; &nbsp; $item&#123;$format_field->&#91;0&#93;&#125; = 
$sublist;
&nbsp; &nbsp; &nbsp; &#125; else &#123;
&nbsp; &nbsp; &nbsp; &nbsp; # scalar; convert to english if necessary and store 
it.
&nbsp; &nbsp; &nbsp; &nbsp; my $field = shift @$fields;
&nbsp; &nbsp; &nbsp; &nbsp; if &#40;exists $valuenames&#123;$format_field&#125; 
&& $field =~ /\d+/&#41; &#123;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $field = 
$valuenames&#123;$format_field&#125;->&#91;$field&#93; || $field;
&nbsp; &nbsp; &nbsp; &nbsp; &#125;
&nbsp; &nbsp; &nbsp; &nbsp; $item&#123;$format_field&#125; = $field;
&nbsp; &nbsp; &nbsp; &nbsp; $prev_field = $field;
&nbsp; &nbsp; &nbsp; &#125;
&nbsp; &nbsp; &#125;

&nbsp; &nbsp; # Single field &#40;as in list of files or list of try status 
lines&#41;
&nbsp; &nbsp; # should not bother with encapsulation in a hash.
&nbsp; &nbsp; if &#40;@$format == 1&#41; &#123;
&nbsp; &nbsp; &nbsp; push @result, values %item;
&nbsp; &nbsp; &#125; else &#123;
&nbsp; &nbsp; &nbsp; push @result, \%item;
&nbsp; &nbsp; &#125;
&nbsp; &#125;

&nbsp; return \@result;
&#125;

open JOBS, '-|', '/opt/openv/netbackup/bin/admincmd/bpdbjobs', '-all_columns'
&nbsp; or die "Couldn't run bpdbjobs&#58; $!";
while &#40;<JOBS>&#41; &#123;
&nbsp; my $job = parse_bpdbjobs&#40;$_&#41;->&#91;0&#93;;

&nbsp; # Can now refer to&#58;
&nbsp; # $job->&#123;'jobid'&#125;,
&nbsp; # $job->&#123;'files'&#125;->&#91;0&#93;,
&nbsp; # $job->&#123;'trypid'&#125;->&#91;0&#93;->&#123;'trystatus'&#125;,
&nbsp; # 
$job->&#123;'trypid'&#125;->&#91;0&#93;->&#123;'trystatuslines'&#125;->&#91;0&#93;,
&nbsp; # etc.

&nbsp; print Dumper&#40;$job&#41;;

&nbsp; # ... Do other stuff with $job here ...
&#125;
close JOBS;


+----------------------------------------------------------------------
|This was sent by rmg AT ua DOT edu via Backup Central.
|Forward SPAM to abuse AT backupcentral DOT com.
+----------------------------------------------------------------------


_______________________________________________
Veritas-bu maillist  -  Veritas-bu AT mailman.eng.auburn DOT edu
http://mailman.eng.auburn.edu/mailman/listinfo/veritas-bu

<Prev in Thread] Current Thread [Next in Thread>
  • [Veritas-bu] Re: bpdbjobs -all_columns, rmg <=