How can I execute this script on version 4.5 and produce the output that is in
the below code.
In our organization we do 2350 backups a day.
I need a way thp parse the logs and sort by server name.. ??
Please advise
#!/usr/bin/perl -w
# $Id: nbujobs,v 1.18 2000/12/19 10:33:57 gustavo Exp $
# Copyright (C) 2000 Fundacao CPqD <gustavo AT cpqd.com DOT br>
=head1 NAME
nbujobs - print the NetBackup jobs from a period
=head1 SINOPSE
B<nbujobs> [B<-h> N | B<-d> N | B<-f> FILE | B<-s>]
=head1 DESCRIPTION
Report about the NetBackup jobs of a period in a Job Monitor like manner.
The period is defined by one of the options:
=over 4
=item B<-h> N
Since N hours ago.
=item B<-d> N
Since N days ago.
=item B<-f> FILE
Since the mtime of FILE.
=item B<-s>
The last backup session period.
=back
=head1 AUTHOR
Gustavo Leite de Mendonça Chaves <gustavo AT cpqd.com DOT br>
=cut
use strict;
use integer;
use Getopt::Long;
use Time::Local;
$ENV{PATH} =
'/bin:/usr/bin:/usr/openv/netbackup/bin:/usr/openv/netbackup/bin/admincmd:/usr/openv/volmgr/bin';
my $usage = "usage: nbujobs [ -h HOURS | -d DAYS | -f FILE | -s ] [--class
CLASS]\n";
#my %args;
#getopts("d:f:h:s", \%args) or die $usage;
use vars qw( $hours_opt $days_opt $file_opt $session_opt $class_opt );
GetOptions('days|d=i' => \$days_opt,
'hours|h=i' => \$hours_opt,
'file|f=s' => \$file_opt,
'session|s=i' => \$session_opt,
'class=s' => \$class_opt)
or die $usage;
my $start = 0;
my $end = time; # time period
my $calc_throughput = 0; # should we calculate throughput?
if (defined $days_opt) {
# N days ago
$start = $end - $days_opt*60*60*24;
} elsif (defined $file_opt) {
# Since file's mtime
die "file $file_opt don't exist\n" unless -e $file_opt;
$start = (stat($file_opt))[9];
} elsif (defined $hours_opt) {
# N hours ago
$start = $end - $hours_opt*60*60;
} elsif (defined $session_opt) {
# During last session
$start = (stat('/usr/openv/netbackup/bin/SESSION_START_CALLED'))[9];
$end = (stat('/usr/openv/netbackup/bin/SESSION_CALLED'))[9];
$end = time if $end < $start;
$calc_throughput = 1;
}
my $kbw = 0; # total kbytes backed up
my $fw = 0; # total files backed up
my %jobs; # job hash
# In NBU3.2 the bpdbjobs utility has a bug that prevents us from
# specifying the format of its output. After more than two months
# waiting for a support call to be solved I decided to fetch the
# information about the jobs directly from the database.
my $jobsdir = '/usr/openv/netbackup/db/jobs';
#my $jobsdir = '/home/gustavo/work/nbu/jobs';
chdir $jobsdir or die "Can't chdir to $jobsdir: $!\n";
opendir(JOBS, $jobsdir) or die "Can't opendir $jobsdir: $!\n";
foreach (grep { $_ !~ /\D/ } readdir(JOBS)) {
job_info($_);
}
close(JOBS);
chdir 'done' or die "Can't chdir to $jobsdir/done: $!\n";
opendir(JOBS, "$jobsdir/done") or die "Can't opendir $jobsdir/done: $!\n";
foreach (grep { $_ !~ /\D/ } readdir(JOBS)) {
job_info($_);
}
close(JOBS);
my ($jid, $jtype, $jstatus, $jclass, $jschedule, $jclient,
$jstarted, $jelapsed, $jtry, $jkbytes, $jfiles);
my @ids = sort { $jobs{$b}->{status} <=> $jobs{$a}->{status}
or $jobs{$a}->{birth} <=> $jobs{$b}->{birth} } keys %jobs;
$= = scalar(@ids) + 2; # avoid multiple headers
foreach $jid (@ids) {
my $job = $jobs{$jid};
$jtype = $job->{type};
$jstatus = $job->{status};
$jclass = $job->{class};
$jschedule = $job->{schedule};
$jclient = $job->{client};
$jstarted = formattime($job->{birth});
$jelapsed = formathour($job->{stamp} - $job->{birth});
$jtry = $job->{try};
$jkbytes = $job->{kbw};
$jfiles = $job->{fw};
write;
}
print "\nTotal size: $kbw KB\n";
print "Total files: $fw\n";
if ($calc_throughput) {
print "Total time: ", formathour($end - $start), "\n";
printf("Throughput: %4.2f KB/s\n", $kbw / ($end - $start));
}
exit 0;
format STDOUT_TOP =
ID Type Status Class Schedule Client Started
Elapsed Try Kbytes Files
------- ---------- ------ --------- -------- ---------- -------------------
-------- --- --------- ------
.
format STDOUT =
@>>>>>> @<<<<<<<<< @>> @<<<<<<<< @<<<<<<< @<<<<<<<<< @<<<<<<<<<<<<<<<<<<
@<<<<<<< @ @>>>>>>>> @>>>>>
$jid, $jtype, $jstatus, $jclass, $jschedule, $jclient, $jstarted, $jelapsed,
$jtry, $jkbytes, $jfiles
.
####################
# Routines
sub job_info {
my $file = shift;
unless (open(JOB, $file)) {
warn "Can't open job file $file: $!\n";
next;
}
my %job = ( type => '-',
status => 0,
class => '-',
schedule => '-',
client => '-',
birth => 0,
try => 0,
stamp => 0,
state => 0,
kbw => 0,
fw => 0,
);
while (<JOB>) {
chomp;
my @cols = split;
my $tag = shift @cols;
if ($tag eq 'JOB_TYPE') {
$job{type} = ('Backup', 'Archive', 'Restore')[$cols[0]];
} elsif ($tag eq 'STATUS') {
$job{status} = $cols[0];
} elsif ($tag eq 'CLASS') {
$job{class} = $cols[1];
} elsif ($tag eq 'SCHEDULE') {
$job{schedule} = $cols[1];
} elsif ($tag eq 'CLIENT') {
$job{client} = $cols[0];
} elsif ($tag eq 'BIRTH_TIME') {
$job{birth} = 0 + $cols[0];
++$job{try};
} elsif ($tag eq '1BEGIN') {
$job{stamp} = 0 + $cols[1];
} elsif ($tag eq 'JOB_STATE') {
$job{state} = $cols[0];
}
}
close(JOB);
return unless $job{birth} >= $start && $job{birth} <= $end;
if (defined $class_opt) {
return unless $class_opt eq $job{class};
}
$jobs{$file} = \%job;
open(JOB, sprintf("%s.%010d.t", $file, $job{birth})) or return;
while (<JOB>) {
chomp;
my @cols = split;
my $tag = shift @cols;
if ($tag eq 'KBW') {
$job{kbw} += $cols[1];
$kbw += $cols[1];
} elsif ($tag eq 'FW') {
$job{fw} += $cols[1];
$fw += $cols[1];
}
}
close(JOB);
}
sub formattime {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
= localtime(shift);
return sprintf('%04d/%02d/%02d %02d:%02d:%02d',
$year + 1900, $mon + 1, $mday,
$hour, $min, $sec);
}
sub formathour {
my $sec = shift;
my $min = $sec / 60; $sec %= 60;
my $hour = $min / 60; $min %= 60;
return sprintf('%02d:%02d:%02d', $hour, $min, $sec);
}
|