Tuesday, June 9, 2009

Intel SQL Modifications For Our NetBackup Backup Reporter Script

Hey There,

Well, I guess it's never to early for an update on a script (most of the times I realize I royally screwed one up occur just minutes after I officially hand it off ;)

Today's update is a follow-up to yesterday's updated NetBackup backup report script for Linux or Unix with Perl. The additions (noted in the comment section at the head of the script) include one user request (support for the Intel SQL module and the Veritas/Symantec required .bch extensioned files) and dusting away a few cobwebs.

Again, if you don't care about the script's output, click here to go straight to the script!

Improvements (I hope ;)

Added:
Support For Intel SQL and OS backups
Reporting of .bch Intel SQL script execution
Explicit close on MAIL file descriptor
Explicit return to STDOUT file descriptor before exit
Minimal signal handling to remove temp file
A bit more error checking and handling

Changed:
Job parsing rule to make exceptiong for .bch files

Modified:
Rule to determine job reporting eligibility

Downsides Noted So Far:
The script now takes about a second and a half to execute on the same system.
I still don't know if it works for everything :)

-------------

Here's some updated output, that you should expect to see (except for the errors, hopefully... ;) Again, you can skip straight to the script by clicking here!



ERROR FREE REPORT - 24 HOUR TIME SPAN - TRUNCATED WITH ELLIPSES...


-------------------
NetBackup Status Report
-----------------------------------------------
Report Span = 06/07/09 ¦ 17:31:47 through 06/08/09 ¦ 17:31:47
-----------------------------------------------


Jobs Completed Successfully!

***************************************************

Server ¦ Policy ¦ Type ¦ Kb ¦ Min Elapsed ¦ Start Date ¦ Time ¦ End Date ¦ Time - File List
***************************************************

host123 ¦ Database_Backup ¦ Default-Application-Backup ¦ 25847840 kb ¦ 14.57 min ¦ 06/07/09 ¦ 22:00:37 ¦ 06/07/09 ¦ 22:15:11
/lafjaiefal_1
***************************************************
host123 ¦ Database_Backup ¦ Default-Application-Backup ¦ 387360 kb ¦ 1.85 min ¦ 06/07/09 ¦ 22:17:10 ¦ 06/07/09 ¦ 22:19:01
/eiwoujlsdjf_1
...
***************************************************
host123-v ¦ NBU ¦ Catalog Backup ¦ 56096 kb ¦ 0.13 min ¦ 06/08/09 ¦ 01:08:52 ¦ 06/08/09 ¦ 01:09:00
***************************************************
host123-v ¦ NBU ¦ Catalog Backup ¦ 56864 kb ¦ 0.13 min ¦ 06/07/09 ¦ 22:23:15 ¦ 06/07/09 ¦ 22:23:23
***************************************************
host123-v ¦ NBU ¦ Catalog Backup ¦ 58400 kb ¦ 0.13 min ¦ 06/07/09 ¦ 19:46:09 ¦ 06/07/09 ¦ 19:46:17
***************************************************
host123-v ¦ NBU ¦ image catalog cleanup ¦ 0 kb ¦ 0.02 min ¦ 06/07/09 ¦ 22:23:25 ¦ 06/07/09 ¦ 22:23:26
***************************************************
host123-v ¦ NBU ¦ image catalog cleanup ¦ 0 kb ¦ 0.02 min ¦ 06/08/09 ¦ 01:09:01 ¦ 06/08/09 ¦ 01:09:02
***************************************************
host123-v ¦ NBU ¦ image catalog cleanup ¦ 0 kb ¦ 0.02 min ¦ 06/08/09 ¦ 13:09:02 ¦ 06/08/09 ¦ 13:09:03
***************************************************
host123-v ¦ NBU ¦ image catalog cleanup ¦ 0 kb ¦ 0.03 min ¦ 06/07/09 ¦ 19:46:18 ¦ 06/07/09 ¦ 19:46:20
***************************************************
intelsql1 ¦ INTEL_SQL ¦ Default-Application-Backup ¦ 4832 kb ¦ 0.55 min ¦ 06/07/09 ¦ 19:39:18 ¦ 06/07/09 ¦ 19:39:51
/MEMMISOIE.MSSQL7.DIKKEISKK\\EKKKDISS.db.model.~.7.001of001.20090607203913..C
...
***************************************************
intelsql1 ¦ INTEL_SQL ¦ FULL ¦ 0 kb ¦ 11.18 min ¦ 06/07/09 ¦ 19:30:00 ¦ 06/07/09 ¦ 19:41:11
nbu_sql_script.bch
***************************************************
intelsql1 ¦ INTEL_OS ¦ DAILY ¦ 1607132 kb ¦ 5.18 min ¦ 06/07/09 ¦ 19:30:00 ¦ 06/07/09 ¦ 19:35:11
ALL_LOCAL_DRIVES
***************************************************
intelsql2 ¦ INTEL_OS ¦ DAILY ¦ 2163310 kb ¦ 16.18 min ¦ 06/07/09 ¦ 19:30:00 ¦ 06/07/09 ¦ 19:46:11
ALL_LOCAL_DRIVES
***************************************************

-----------------------------------------------



REPORT WITH ERRORS IN IT - 48 HOUR TIME SPAN - TRUNCATED WITH ELLIPSES...


NetBackup Status Report
-----------------------------------------------
Report Span = 06/06/09 ¦ 17:51:26 through 06/08/09 ¦ 17:51:26
-----------------------------------------------

Jobs With Errors To Report!

***************************************************
Server ¦ Policy ¦ Type ¦ Kb ¦ Min Elapsed ¦ Start Date ¦ Time ¦ End Date ¦ Time - Error - File List
***************************************************

host456 ¦ Database_Backup ¦ warm_back ¦ 0 kb ¦ 13.90 min ¦ 06/06/09 ¦ 23:24:02 ¦ 06/06/09 ¦ 23:37:56
ERROR: the backup failed to back up the requested files!!!
/usr/local/bin/warm_backup.sh
***************************************************
host456 ¦ Database_Backup ¦ warm_back ¦ 0 kb ¦ 15.28 min ¦ 06/07/09 ¦ 23:24:09 ¦ 06/07/09 ¦ 23:39:26
ERROR: the backup failed to back up the requested files!!!
/usr/local/bin/warm_backup.sh
***************************************************

-----------------------------------------------

Jobs Completed Successfully!

***************************************************

Server ¦ Policy ¦ Type ¦ Kb ¦ Min Elapsed ¦ Start Date ¦ Time ¦ End Date ¦ Time - File List
***************************************************

host456 ¦ Database_Backup ¦ Default-Application-Backup ¦ 12589911 kb ¦ 10.77 min ¦ 06/06/09 ¦ 23:00:20 ¦ 06/06/09 ¦ 23:11:06
/fsladfjf_1_1
***************************************************
host456 ¦ Database_Backup ¦ Default-Application-Backup ¦ 12589911 kb ¦ 10.87 min ¦ 06/07/09 ¦ 23:00:14 ¦ 06/07/09 ¦ 23:11:06
/fajlfasljf_1_1
***************************************************
...
SEE ABOVE :)
***************************************************

-----------------------------------------------





Creative Commons License
bpreport.pl by Mike Golvach is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
Based on a work at linuxshellaccount.blogspot.com.
Permissions beyond the scope of this license may be available at http://linuxshellaccount.blogspot.com


#!/usr/bin/perl
#
# bpreport.pl - 2009 Mike Golvach - eggi@comcast.net
#
#bpreport.pl by Mike Golvach is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License. Based on a work at linuxshellaccount.blogspot.com. Permissions beyond the scope of this license may be available at http://linuxshellaccount.blogspot.com.
#
# 06/08/09:
# Added: Support For Intel SQL And OS backups
# Added: Reporting of 0kb .bch Intel SQL script execution
# Added: Explicit close on MAIL file descriptor
# Added: Explicit return to STDOUT file descriptor before exit
# Added: Minimal signal handling to remove temp file
# Added: A bit more error checking and handling
# Modified: Job parsing rule to make exceptiong for .bch files
# Modified: Rule to determine job reporting eligibility
#

$SIG{INT} = \&bail;

$first_tmp = $$;
$offset = $ARGV[0];

if ( -f "tmp.$first_tmp" ) {
unlink("tmp.$first_tmp")
}

if ( $#ARGV != 0 ) {
print "Usage: $0 TimeInSecondsToReportBack\n";
exit(1)
}

$sisosig = system("/usr/openv/netbackup/bin/admincmd/bpdbjobs -all_columns >>tmp.$first_tmp");

if ( $sisosig > 0 ) {
bail();
}

open(FT, "<tmp.$first_tmp");
@all_jobs = <FT>;
close(FT);

if ( -f "tmp.$first_tmp" ) {
unlink("tmp.$first_tmp")
}

$global_error_flag = 0;
$separator = "***************************************************";
$hostname=`hostname`;

foreach $job (@all_jobs) {
@file_list="";
@job = split(/,/, $job);
chomp($job[14]);
if ( $job[14] =~ /^$/ ) {
$job[14] = "0";
}
$error_flag = 0;
$report_time = $job[8];
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($job[8]);
$today = parse_date($sec,$min,$hour,$mday,$mon,$year,$wday);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($job[10]);
chomp($today_end = parse_date($sec,$min,$hour,$mday,$mon,$year,$wday));
if ( $today_end =~ /12\/31\/69/ ) {
$today_end = "JOB IN PROGRESS";
}
$today_span_pre = ( $job[9] / 60 );
$today_span = sprintf("%.2f min", $today_span_pre);
$actual_time = time;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$right_now = parse_date($sec,$min,$hour,$mday,$mon,$year,$wday);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time-$offset);
$back_then = parse_date($sec,$min,$hour,$mday,$mon,$year,$wday);
report_span($report_time, $actual_time, $offset);
next if $dont_report;
if ( $job[3] > 1 ) {
@error_condition = `/usr/openv/netbackup/bin/admincmd/bperror -S $job[3]`;
chomp($error_condition = $error_condition[0]);
$job[3] = $error_condition;
$error_flag = 1;
$global_error_flag = 1;
}
### next if ( $job[6] eq "backuphost" && $job[14] == 0 && ! $error_flag );
next if ( $job[6] eq "backuphost" && ! $error_flag );
$job[$file_list] = $job[31] if ( $job[4] =~ /Intel_SQL/ && $job[5] =~ /FULL/ );
$file_list=32;
$file_list_still_going = 1;
$just_starting = 1;
while ($file_list_still_going) {
if ( ( $job[$file_list] =~ /(\/¦\\¦ALL)/ ) ¦¦ ( $job[4] =~ /Intel_SQL/ & $job[$file_list] =~ /\.bch/ ) ) {
if ( $just_starting ) {
push(@file_list, "$job[$file_list] ");
$file_list++;
$just_starting = 0;
} else {
push(@file_list, "¦ $job[$file_list] ");
$file_list++;
}
} else {
$file_list_still_going = 0;
}
}
if ( ! $job[5] && ! $job[6] ) {
if ( $job[42] =~ /^.*(image catalog cleanup).*$/ ) {
$job[6] = $job[25];
$job[5] = $job[42];
$job[5] =~ s/^.*(image catalog cleanup).*$/$1/;
$job[4] = "NBU";
} else {
$job[5] = "Server UNKNOWN";
$job[4] = "NBU";
}
} elsif ( ! $job[5] && $job[6] ) {
if ( $job[42] =~ /^.*(Catalog Backup).*$/ ) {
$job[6] = $job[25];
$job[5] = $job[42];
$job[5] =~ s/^.*(Catalog Backup).*$/$1/;
$job[4] = "NBU";
} else {
$job[5] = "Policy UNKNOWN";
$job[4] = "NBU";
}
}
if ( $#file_list == 0 ) {
push(@job_successes, "$job[6] ¦ $job[4] ¦ $job[5] ¦ $job[14] kb ¦ $today_span ¦ $today ¦ $today_end\n$separator\n");
} elsif ( $error_flag ) {
push(@job_errors, "$job[6] ¦ $job[4] ¦ $job[5] ¦ $job[14] kb ¦ $today_span ¦ $today ¦ $today_end\nERROR: ${error_condition}!!!\n@{file_list}\n$separator\n");
} else {
push(@job_successes, "$job[6] ¦ $job[4] ¦ $job[5] ¦ $job[14] kb ¦ $today_span ¦ $today ¦ $today_end\n@file_list\n$separator\n");
}
}

$¦=1;

## Don't send out okay mails if everything is fine)
#if ( @job_errors ) {

open(MAIL, "¦/usr/lib/sendmail -t");
select(MAIL);
if ( ( $#job_errors < 0 )&& ( $#job_successes < 0 ) ) {
print "Subject: NO JOBS: $hostname NetBackup Status Report - $right_now\n";
} elsif ( @job_errors ) {
print "Subject: ERRORS: $hostname NetBackup Status Report - $right_now\n";
} else {
print "Subject: ALL OK: $hostname NetBackup Status Report - $right_now\n";
}
print "From: them\@xyz.com\n";
print "Reply-To: us\@xyz.com\n";
print "To: us\@xyz.com\n";
print "\n\n";
print "NetBackup Status Report\n";
print "-----------------------------------------------\n";
print "Report Span = $back_then through $right_now\n";
print "-----------------------------------------------\n";
print "\n";
if ( ( $#job_errors < 0 )&& ( $#job_successes < 0 ) ) {
print "No Activity To Report! Check If NetBackup Is Running!\n";
print "-----------------------------------------------\n";
} else {
if ( @job_errors ) {
print "Jobs With Errors To Report!\n\n$separator\n";
print "Server ¦ Policy ¦ Type ¦ Kb ¦ Min Elapsed ¦ Start Date ¦ Time ¦ End Date ¦ Time - Error - File List\n";
print "$separator\n\n";
@job_errors = sort @job_errors;
$job_error_count = @job_errors;
if ( $job_error_count ) {
print "@job_errors\n";
} else {
print "NO ERRORS TO REPORT. REPORT MAY BE IN ERROR!!!\n\n"
}
print "-----------------------------------------------\n";
}
if ( @job_successes ) {
print "\nJobs Completed Successfully!\n\n$separator\n\n";
print "Server ¦ Policy ¦ Type ¦ Kb ¦ Min Elapsed ¦ Start Date ¦ Time ¦ End Date ¦ Time - File List\n";
print "$separator\n\n";
@job_successes = sort @job_successes;
print "@job_successes\n";
print "-----------------------------------------------\n";
}
}
select(STDOUT);
close(MAIL);
#} # End of possibly-no-mail section
exit(0);

sub parse_date {

my ($sec,$min,$hour,$mday,$mon,$year,$wday) = @_;
%months = qw(0 Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec);
%weekdays = qw(0 Sun 1 Mon 2 Tue 3 Wed 4 Thu 5 Fri 6 Sat);
if ( $sec < 10 ) {
$sec = "0" . $sec;
}
if ( $min < 10 ) {
$min = "0" . $min;
}
if ( $hour < 10 ) {
$hour = "0" . $hour;
}
if ( $mday < 10 ) {
$mday = "0" . $mday;
}
if ( $yday < 10 ) {
$yday = "0" . $yday;
}
$mon = $mon + 1;
if ( $mon < 10 ) {
$mon = "0" . $mon;
}
$wday = $weekdays{$wday};
$year = 1900 + $year;
$year =~ s/^..(.*)$/$1/;
$nice_date = "${mon}/${mday}/$year ¦ ${hour}:${min}:$sec";
}

sub report_span {

my ($report_time,$actual_time,$offset) = @_;
$dont_report = 0;
$more_than_offset_hours_old = $actual_time - $report_time;
if ( $more_than_offset_hours_old > $offset ) {
$dont_report = 1;
}
}

sub bail {

print "BAILING\n";
if ( -f "tmp.$first_tmp" ) {
unlink("tmp.$first_tmp")
}
exit(2);
}




, Mike




Banner for College Student-Oriented Sites (728 version 1)





Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.