NetBackup 24 hr Turnover Report (Perl it up)

Hello Again,

I was searching thru some of my scripts and came across a good one I have been using for years.  Not as much now that Symantec has Operations Center Analytics with NetBackup 7.x, but it’s still very useful as a 24 backup turnover report.  Please enjoy it, and be careful to remove some of my comments before you give it a whirl…. Thanks for Reading

#The following perl script reports on Backup Status for the last 24 Hours

# Lets do some variables ##############################
$bperror = "f:/veritas/netbackup/bin/admincmd/bperror.exe"; "Create a variable for the bperror and bpdbjobs commands, to create the report"
$bpdbjobs = "f:/veritas/netbackup/bin/admincmd/bpdbjobs.exe";
$master = "masterserver.widget.com"; "NetBackup Master server name"
$recipients = "lisgtofemails\@widget.com"; "List of people or groups to email"
$knownsender = "known\@widget.com";
$fromsender = "from\@widget.com";
$blatpath = "f:/blat/blat.exe "; "Variable the blah email program
$subject = "Netbackup Daily Status Report for Widget"; "Subject for the email"
$site = "Widget Chicago";
$outfile = "f:/abbott/temp/daily_turnover.log"; "Create the log file to push all data"

# Open the OUTPUT Stream
open (OUTPUT, "> $outfile");
select OUTPUT;
print "\n";
print "\n";
print "NetBackup Backup Status Report for $site. This report covers the last 24 hours.\n";
print "\n";
print "\n";

##############################################################################
# Runs bperror to run a Detailed report on all backups for previous 24 hours #
##############################################################################

# Run the bperror command
open (BPERROR, "$bperror -M $master -t BACKSTAT -U -hoursago 24 |") || die "Cannot open $bperror: $!";

# Populate the backups array with only the lines containing backup job information finds thing that has digits surrounded by spaces and removes them
while (<BPERROR>) {
	chomp;
	if ( $_ =~ /^\s*\d+\s+.*$/ ) {
		push @backups, $_;
	}
}

close BPERROR;

# printBanner tells wether or not the banner has been already printed. 0 means not printed yet.
$printBanner=0;

# Check and print all the backups with status greater than 1.
foreach $item (@backups) {
	my ( $status ) = split (' ', $item);
	if ( $status > 1 ) {
		if ( $printBanner == 0 ) {
			$printBanner = 1;
			print "\n";
			print "The following backup jobs failed to complete! Please review status code to determine resolution!\n";
			print "\n";
			print "STATUS CLIENT        POLICY           SCHED      SERVER      TIME COMPLETED\n";
		}
		print "$item\n"
	}
}

# Check and print all the backups with status equal to 1.
$printBanner=0;
foreach $item (@backups) {
	my ( $status ) = split (' ', $item);
	if ( $status == 1 ) {
		if ( $printBanner == 0 ) {
			$printBanner = 1;
			print "\n";
			print "The following backup jobs finished partially successful. This is usually because open files have been skipped during the backup.\n";
			print "\n";
			print "STATUS CLIENT        POLICY           SCHED      SERVER      TIME COMPLETED\n";
		}
		print "$item\n"
	}
}

# Check and print all the backups with status equal to 0.
$printBanner=0;
foreach $item (@backups) {
	my ( $status ) = split (' ', $item);
	if ( $status == 0 ) {
		if ( $printBanner == 0 ) {
			$printBanner = 1;
			print "\n";
			print "The following backup jobs finished successfully.\n";
			print "\n";
			print "STATUS CLIENT        POLICY           SCHED      SERVER      TIME COMPLETED\n";
		}
		print "$item\n"
	}
}

# Go through the backup report and keep the last DB backup and all the restores. Grabbing DB Backup, any restores, and any active jobs
open (BPDBJOBS, "$bpdbjobs -report -M $master |") or die "Cannot open $bpdbjobs: $!";
while ( <BPDBJOBS> ){
	chomp;
	if ( $_ =~ /^\s*\d+\s+DB Backup\s+.*$/ ) {
		$lastDbBackup = $_;
	} elsif ( $_ =~ /^\s*\d+\s+Restore\s+.*$/ ) {
		push @restores, $_;
	} elsif ( $_ =~ /^\s*\d+\s+\w+\s+Active\s+.*$/ ) {
		push @actjobs, $_;
	}
}
close BPDBJOBS;

#Print Active Backup Jobs.

foreach $ActiveBackup ( @actjobs ) {
	print "\n";
	print "----------Netbackup Active Backups-----------\n";
	# Print the last DB backup status.
	print "JobID      Type  State Status      Policy Schedule                       Client               Dest Media Svr Active PID\n";
	print "$ActiveBackup\n";
	print "---------------------------------------------\n";
	print "\n";
}

# Split up the DB backup into meaningful variables
( $DBjobID, $DBtype, $DBtypeExt, undef, $DBstatus) = split ' ', $lastDbBackup;

# Print the last DB backup status.
print "\n";
print "----------Netbackup Catalog Backup-----------\n";
print " JobID -- $DBjobID\n Type -- $DBtype $DBtypeExt \n";
( $DBstatus == 0 ) ? print " Status -- Successful\n" : print "Status -- Unsuccessful\n";
print "---------------------------------------------\n";
print "\n";

# Print the status of all restores.

# Go through all the restores and print the status and other information.
foreach $restore ( @restores ) {
	( $RjobID, $Rtype, undef, $Rstatus, $Rclient) = split ' ', $restore;
	print "----------Netbackup Restores-----------------\n";
	print " JobID -- $RjobID\n Type -- $Rtype\n Client -- $Rclient\n";
	( $Rstatus == 0 ) ? print " Status -- Successful\n" : print " Status -- Unsuccessful\n";
	print "---------------------------------------------\n";
}

######################################
# Blat the log file to proper people #
######################################

close OUTPUT;

$commandline = $blatpath;
$commandline .= $outfile;
$commandline .= " -s \"$subject\" " if $subject;
$commandline .= "-t \"$recipients\" " if $recipients;
$commandline .= "-f $fromsender " if $fromsender;
$commandline .= "-c $ccaddress " if $ccaddress;
print "\n";
print "\$commandline \= $commandline";
print "\n";
system($commandline);

Leave a Reply