Veritas-bu

[Veritas-bu] Exclude lists on Unix clients

2011-12-07 03:52:17
Subject: [Veritas-bu] Exclude lists on Unix clients
From: pwhelan0610 <nbu-forum AT backupcentral DOT com>
To: VERITAS-BU AT MAILMAN.ENG.AUBURN DOT EDU
Date: Wed, 07 Dec 2011 00:52:09 -0800
New revised version. Automatically gets the version information. The -v switch 
will allow you to ONLY get the version information.
================== Begin Code ============================

#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Std;


# To turn on debuging (i.e. more information) specify -d on the command line
our $opt_d = 0;

# To get ONLY the version information specify -v on the command line
our $opt_v = 0;

getopts('dv');

our $debug = $opt_d;

my $uname = `uname -n`;
chomp $uname;

# Desiginate where to write the in/exclude files (must be fully qualified path)
our $PWD = $ENV{PWD};
our $output_dir = "$PWD/EI_${uname}";
if ( ! -d $output_dir ) { mkdir $output_dir }


# Location of bp.... commands
our $nbadmin = "/usr/openv/netbackup/bin/admincmd";

# Generate a list of policies
our @policy_list = `$nbadmin/bppllist`;

# Used the get output of the bpgetconfig command. Only need for debut purposes
our @status = ();


foreach my $policy (@policy_list) {
        chomp $policy;

        # Get the individual policy information
        my @policy = `$nbadmin/bppllist $policy -l`;

        # Extract the info line
        my @info = grep /^INFO /, @policy;

        # If the policy type is not standard, ignore
        if ( (split /\s+/, $info[0])[1] != 0 ) { next }

        # If the policy is inactive, ignore
        if ( (split /\s+/, $info[0])[11] != 0 ) { next }

        # Pull out the clients for this policy and then keep only the client 
names
        my @clients = grep /^CLIENT /, @policy;
        @clients = map { (split /\s+/, $_)[1]} @clients;

        # Pull out the schedules for this policy and then keep only the 
schedule names
        my @schedules = grep /^SCHED /,@policy;
        @schedules = map { (split /\s+/, $_)[1]} @schedules;

        # Now for each client
        foreach my $client (@clients) {

                if ($debug != 0) { print STDERR "$client $policy\n"; }

                # Be sure the client is at leas pingable otherewise the 
bpgetconfig command will take a long time to fail
                system("ping -c 1 -W 5 $client > /dev/null 2>&1");
                if ($? != 0  ) { print STDERR "$client not pingable\n"; next }

                open VERSION, ">$output_dir/version.$client" or die "Couldn't 
open $output_dir/version.$client for output: $!\n";
                print VERSION "============= Version Check of $client 
===================\n";
                print VERSION `bpgetconfig -t -A -g $client 2>&1`;
                print VERSION "============= End Version Check of $client 
===================\n";
                close VERSION;

                if ( ! $opt_v ) {
                        # get, if any, the basic include and/or exclude files. 
(i.e. /usr/openv/netbackup/exclude_list or include_list)
                        @status = `$nbadmin/bpgetconfig -e 
\"/$output_dir/exclude.$client.basic\" \"$client\" 2>&1`;
                        if ($? != 0 && $debug != 0  ) { print STDERR "$client 
bpgetconfig -exclude no policy failed with $?\n @status" }
                        @status = `$nbadmin/bpgetconfig -i 
\"/$output_dir/include.$client.basic\" \"$client\" 2>&1`;
                        if ($? != 0  && $debug != 0 ) { print STDERR "$client 
bpgetconfig -include no policy failed with $?\n @status" }

                        # get, if any, the policy include and/or exclude files. 
(i.e. /usr/openv/netbackup/exclude_list.policy or include_list.policy)
                        @status = `$nbadmin/bpgetconfig -e 
\"/$output_dir/exclude.$policy.$client\" \"$client\" \"$policy\" 2>&1`;
                        if ($? != 0 && $debug != 0  ) { print STDERR "$client 
bpgetconfig -exclude policy only failed with $?\n @status" }
                        @status = `$nbadmin/bpgetconfig -i 
\"/$output_dir/include.$policy.$client\" \"$client\" \"$policy\" 2>&1`;
                        if ($? != 0 && $debug != 0  ) { print STDERR "$client 
bpgetconfig -include policy only failed with $?\n @status" }

                        # Now for each schedule in the policy (i.e. 
/usr/openv/netbackup/exclude.policy.schedule=
                        foreach my $schedule (@schedules) {
                                if ($debug != 0) { print STDERR "$client 
$policy $schedule\n"; }
                                @status = `$nbadmin/bpgetconfig -e 
\"/$output_dir/exclude.$policy.$client.$schedule\" \"$client\" \"$policy\" 
\"$schedule\" 2>&1`;
                                if ($? != 0 && $debug != 0  ) { print STDERR 
"$client bpgetconfig -exclude with policy and schedule failed with $?\n 
@status" }
                                @status = `$nbadmin/bpgetconfig -i 
\"/$output_dir/include.$policy.$client.$schedule\" \"$client\" \"$policy\" 
\"$schedule\" 2>&1`;
                                if ($? != 0 && $debug != 0  ) { print STDERR 
"$client bpgetconfig -include with policy and schedule failed with $?\n 
@status" }
                        }
                }
        }

        # If any of the bpgetconfigs work the ouput will be in the file name 
following the -e or -i
}

exit;
====================== End of code ========================

Enjoy.

Patrick

+----------------------------------------------------------------------
|This was sent by netbackup AT whelan-consulting.co DOT uk via Backup Central.
|Forward SPAM to abuse AT backupcentral DOT com.
+----------------------------------------------------------------------


_______________________________________________
Veritas-bu maillist  -  Veritas-bu AT mailman.eng.auburn DOT edu
http://mailman.eng.auburn.edu/mailman/listinfo/veritas-bu