Netbackup Scripts – clean-jobs

NetbackupFar too many jobs end up in the Java GUI or in the bpdbjobs output… If the job is successful, why does it stick around for three days. This hides the real problems that may have occurred.

My solution is a cron job that deletes successful jobs (Status Code of 0 and 1).


#!/usr/bin/perl

use strict;

my $jobid; my $type; my $state; my $status; my $policy;
my $sched; my $client; my $media_server; my $pid; my @jobs;
my $delete_string;

my $cmd='/usr/openv/netbackup/bin/admincmd/bpdbjobs';
chomp(my @output=`$cmd`);
shift @output; # Skip the header record..

foreach (@output)
s/Image Delete/Image_Delete/;
($jobid, $type, $state, $status, $policy, $sched, $client, $media_server, $pid) = split (" ",$_);
 if (( $state eq "Done") && (SafeCode($status)==0)) {
 push @jobs, $jobid;
 }
}

$delete_string = shift @jobs;
foreach (@jobs) {
 $delete_string .= ",";
}

if (defined($delete_string)) {
 `$cmd -delete $delete_string`
}

exit;

sub SafeCode {
 my $query = @_[0];
 my @safecodes = qw / 0 1 /;
 foreach (@safecodes) {
 if ( $query == $_ ) {
 return 0;
 }
 }
 return -1;
}