Veritas-bu

[Veritas-bu] Daily Backup Status reports

2001-06-28 12:10:28
Subject: [Veritas-bu] Daily Backup Status reports
From: jmeyer AT ptc DOT com (Jonathan Meyer)
Date: Thu, 28 Jun 2001 12:10:28 -0400
I have a perl script which runs daily from cron to email me the status
of backups.

It reformats the output from "bperror -backstat -hoursago 24" in a way
I find useful.

This script parses the output and sorts it by class and client.  It
groups all the attempts for each class and client together.  Once it
has grouped all the attempts for each specific backup, it sorts the
output according to the best result which each specific backup got in
the last 24 hours.

Then it prints a sorted list starting with all the backups which have
gotten a status 0 within the last 24 hours.  Failed trys are included
in the list, but any backups in this first section have succeeded
within 24 hours.

Then it prints a section of backups which got at least a status 1.

Lastly, it prints all the attempts for classes and clients which have
not succeeded within 24 hours.

I am including the script below.

--------------------------------------------------
Jonathan Meyer
(781)370-6594
UNIX Systems Administrator
Paramtric Technology Corporation
--------------------------------------------------

#!/usr/local/bin/perl -w

# The bperror command returns the status from all the backups in the
# last 24 hours.

open STATS, "bperror -U -backstat -hoursago 24|"
    or die "could not open backstat: $!";
my @stats = <STATS>;
close STATS;

my $header = "STATUS CLIENT        CLASS            SCHED" .
    "      SERVER      TIME COMPLETED\n";

# Sort all of the stats into a hash of hashes.
my ( $client, $class );
for (@stats){
    /^STATUS/ && next;
    # If the line begins with numeric status, parse out the class and
    # client; otherwise, the line is part of a multi-line entry.
    if ( /^\s*\d+\s/ ) {
        ( $client, $class ) = (split)[1,2];
        $hash{$client}{$class} .= $_;
        next;
    }
    $hash{$client}{$class} .= $_;
}

# Initialize variables to nulls.
my ($ok, $partial, $failed) = ( '', '', '' );

for $client ( sort(keys %hash) ){
    for $class ( sort(keys %{$hash{$client}}) ) {
        my $data = $hash{$client}{$class};
        if ( $data =~ /^\s*0\s/m ) {
            $ok .= $data;
        } elsif ( $data =~ /^\s*1\s/m ) {
            $partial .= $data;
        } else {
            $failed .= $data;
        }
    }
}

print "$header$ok$header$partial$header$failed";


<Prev in Thread] Current Thread [Next in Thread>