#!/usr/bin/perl -w # parsing of bpdbjobs lifted from: # http://www.backupcentral.com/cgi-bin/netbackup-fom?_highlightWords=bpdbjobs&file=194 # and cleaned up a bit # # Feed bpdbjobs -all_columns in, get warnings about too-slow backups # out. # # 20050124, gr use strict; use POSIX; use Data::Dumper; my @job_info_labels = ('jobid', 'jobtype', 'state', 'status', 'class', 'sched', 'client', 'server', 'start', 'elapsed', 'end', 'stunit', 'try', 'operation', 'kbytes', 'files', 'path_last_written', 'percent', 'jobpid', 'owner', 'subtype', 'classtype', 'schedtype', 'priority', 'group', 'master_server', 'retention_units', 'retention_period', 'compression', 'kbyteslastwritten', 'fileslastwritten', 'filelistcount'); my @job_try_labels_1 = ('trypid', 'trystunit', 'tryserver', 'trystarted', 'tryelapsed', 'tryended', 'trystatus', 'trystatusdescription', 'trystatuscount'); my @job_try_labels_2 = ('trykbyteswritten','tryfileswritten'); my @vault_info_labels = ('unknown1', 'unknown2', 'unknown3', 'vltrobot', 'vltname', 'vltprofile', 'vltsid', 'vltejects', 'unknown4', 'unknown5', 'unknown6', 'unknown7'); # Minimum KB/s write speed; anything below this will be reported. my $min = 1024; my $sudo = ''; $sudo = "sudo " if ($> != 0); # Jacked from the (TOTALLY UNDOCUMENTED SO I CAN'T USE IT WITHOUT # LOTS OF PAIN) NBU::Job. my %op_codes = ( -1 => '---', 25 => 'Waiting', 2 => 'Connecting', 26 => 'Connecting', 0 => ' ? ', 27 => 'Mounting', 29 => 'Positioning', 3 => 'Writing', 35 => 'Writing', 5 => 'Duplicating', ); # The rest are just from bpdbjobs(1M) (operation isn't discussed # there, jerks). my %jt_codes = ( 0 => 'Backup', 1 => 'Archive', 2 => 'Restore', 3 => 'Verify', 4 => 'Duplication', 5 => 'Import', 6 => 'DB Backup', 7 => 'Vault', ); my %state_codes = ( 0 => 'Queued', 1 => 'Active', 2 => 'Requeued', 3 => 'Done', ); my ($job, @columns, $idx, @files, @trylist, $trydata, @trystatuslines, @jobs); my $quiet = 0; if ($#ARGV >= 0) { while (@ARGV) { $_ = shift @ARGV; $quiet = 1 if ($_ =~ /^-q/); } } #while(<>) { foreach(`$sudo /usr/openv/netbackup/bin/admincmd/bpdbjobs -report -all_columns`) { chomp; # Yeah, they really include escaped ,s; ditch them # ... only but there are some legit \\, situations on Windows $_ =~ s#\\\\#//#g; # You can also specify multiple STUs for vaults through different # duplication rules, and there are separated by /, / in the -all_columns # output. (Could I make this stuff up? No.) $_ =~ s/, /; /g; $_ =~ s/\\[,;]//g; undef($job); @columns = split(','); $idx = 0; foreach my $label (@job_info_labels) { $job->{$label} = $columns[$idx]; $idx++; } @files = (); if ($job->{'filelistcount'} > 0) { @files = @columns[$idx..$idx+$job->{'filelistcount'}-1]; } $job->{'files'} = [@files]; $idx += $job->{'filelistcount'} ; $job->{'trycount'} = $columns[$idx]; # Now get the try data. Within the try data # is a list of try status lines. @trylist = (); $idx++; for (1..$job->{'trycount'}) { undef($trydata); foreach my $trylabel ( @job_try_labels_1 ) { $trydata->{$trylabel} = $columns[$idx]; $idx++; } @trystatuslines = @columns[$idx..$idx+$trydata->{'trystatuscount'}-1]; $trydata->{'trystatuslines'} = [@trystatuslines]; $idx += $trydata->{'trystatuscount'}; foreach my $trylabel ( @job_try_labels_2 ) { $trydata->{$trylabel} = $columns[$idx]; $idx++; } push @trylist, $trydata; } $job->{'trylist'} = [@trylist]; foreach my $vltlabel (@vault_info_labels) { $job->{$vltlabel} = $columns[$idx]; $idx++; } push @jobs, $job; } #print Dumper(@jobs); my @powers = qw(KB MB GB TB PB); my (@trylines, $base, $power); my %seen; foreach $job (@jobs) { for ($idx = 1; $idx <= $job->{'trycount'}; $idx++) { $trydata = ${$job->{'trylist'}}[$idx - 1]; if (defined($trydata->{'trykbyteswritten'}) && ($trydata->{'trykbyteswritten'} > 0) && defined($trydata->{'tryelapsed'}) # only report on jobs that run longer than 5 minutes; # less than that and the speeds are garbage numbers && ($trydata->{'tryelapsed'} > 300)) { $base = $trydata->{'trykbyteswritten'} / $trydata->{'tryelapsed'}; if ($base < $min && ! defined($seen{$job->{'client'}})) { $seen{$job->{'client'}} = 1; $power = 0; while ($base > 1024) { $base /= 1024; $power++; } printf "%-10s in %-20s wrote at %.2f %s/sec in jobid %s try $idx\n", $job->{'client'}, $job->{'class'}, $base, $powers[$power], $job->{'jobid'}; } } } }