Coincidentally, I wrote this just last week:

#!/usr/bin/perl

use Data::Dumper;

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

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

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

sub parse_bpdbjobs {
  my ($fields, $format, $repeat) = @_;

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

  $format = $lineformat unless (defined $format);
  $repeat = 1 unless (defined $repeat);

  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 [EMAIL PROTECTED];
&#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 [EMAIL PROTECTED] via Backup Central.
|Forward SPAM to [EMAIL PROTECTED]
+----------------------------------------------------------------------


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

Reply via email to