| 1 | #!/usr/local/bin/perl -w | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | use Getopt::Std; | ||
| 6 | |||
| 7 | my %opts; | ||
| 8 | getopts('?ucxd', \%opts); | ||
| 9 | |||
| 10 | if ($opts{'?'}) { | ||
| 11 | print STDERR <<EOT; | ||
| 12 | Usage: coverage.pl [-x] [-u|-c] [hostname [hostname ...]] | ||
| 13 | Options: | ||
| 14 | -u Only list uncovered mountpoints | ||
| 15 | -c Only list covered mountpoints | ||
| 16 | |||
| 17 | -x Produce xml output | ||
| 18 | EOT | ||
| 19 | exit; | ||
| 20 | } | ||
| 21 | |||
| 22 | |||
| 23 | use NBU; | ||
| 24 | NBU->debug($opts{'d'}); | ||
| 25 | |||
| 26 | NBU::Class->populate; | ||
| 27 | |||
| 28 | my @clients; | ||
| 29 | if ($#ARGV > -1 ) { | ||
| 30 | for my $clientName (@ARGV) { | ||
| 31 | push @clients, NBU::Host->new($clientName); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | else { | ||
| 35 | NBU::Host->populate(1); | ||
| 36 | @clients = (sort {$a->name cmp $b->name} (NBU::Host->list)); | ||
| 37 | } | ||
| 38 | |||
| 39 | if ($opts{'x'}) { | ||
| 40 | print "<?xml version=\"1.0\"?>\n"; | ||
| 41 | print "<coverage>\n"; | ||
| 42 | } | ||
| 43 | foreach my $client (@clients) { | ||
| 44 | my $cn = $client->name; | ||
| 45 | |||
| 46 | if ($opts{'x'}) { | ||
| 47 | print " <host name=\"$cn\">"; | ||
| 48 | } | ||
| 49 | else { | ||
| 50 | print "$cn:"; | ||
| 51 | } | ||
| 52 | my %mountPointList = $client->coverage; | ||
| 53 | foreach my $mp (sort (keys %mountPointList)) { | ||
| 54 | my $clR = $mountPointList{$mp}; | ||
| 55 | my $mpStatus = ($opts{'x'} ? " <mountpoint path=\"$mp\">" : "\t$mp:"); | ||
| 56 | my $disposition; | ||
| 57 | my $covered; | ||
| 58 | if ($clR) { | ||
| 59 | foreach my $class (@$clR) { | ||
| 60 | my $cn = $class->name; | ||
| 61 | if ($class->active) { | ||
| 62 | if ($opts{'c'} || !$opts{'u'}) { | ||
| 63 | $mpStatus .= ($opts{'x'} ? "\n <covered policy=\"$cn\" active=\"1\" />" : " $cn"); | ||
| 64 | } | ||
| 65 | $covered += 1; | ||
| 66 | } | ||
| 67 | else { | ||
| 68 | if ($opts{'u'} || !$opts{'c'}) { | ||
| 69 | $mpStatus .= ($opts{'x'} ? "\n <covered policy=\"$cn\" active=\"0\" />" : " ($cn)"); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | else { | ||
| 75 | $mpStatus .= " not covered" if (!$opts{'x'}); | ||
| 76 | } | ||
| 77 | $mpStatus .= "\n </mountpoint>" if ($opts{'x'}); | ||
| 78 | if ((!$opts{'u'} && !$opts{'c'}) || | ||
| 79 | ($opts{'u'} && !$covered) || | ||
| 80 | ($opts{'c'} && $covered)) { | ||
| 81 | print "\n$mpStatus"; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | if (!$opts{'x'}) { | ||
| 86 | if ($opts{'c'} || !$opts{'u'}) { | ||
| 87 | my $sep = "\n\tadditional active classes are: "; | ||
| 88 | foreach my $class ($client->classes) { | ||
| 89 | if ($class->active && !$class->providesCoverage) { | ||
| 90 | print $sep.$class->name; | ||
| 91 | $sep = " "; | ||
| 92 | } | ||
| 93 | } | ||
| 94 | } | ||
| 95 | |||
| 96 | if ($opts{'u'} || !$opts{'c'}) { | ||
| 97 | my $sep = "\n\tadditional inactive classes are: "; | ||
| 98 | foreach my $class ($client->classes) { | ||
| 99 | if (!$class->active && !$class->providesCoverage) { | ||
| 100 | print $sep."(".$class->name.")"; | ||
| 101 | $sep = " "; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | } | ||
| 105 | } | ||
| 106 | print "\n"; | ||
| 107 | if ($opts{'x'}) { | ||
| 108 | print " </host>\n\n"; | ||
| 109 | } | ||
| 110 | } | ||
| 111 | print "</coverage>\n" if ($opts{'x'}); | ||
| 112 | |||
| 113 | =head1 NAME | ||
| 114 | |||
| 115 | coverage.pl - Analyze Which File-Systems (if any) Are Backed Up | ||
| 116 | |||
| 117 | =head1 SYNOPSIS | ||
| 118 | |||
| 119 | coverage.pl [options...] [hostname [hostname ...]] | ||
| 120 | |||
| 121 | =head1 DESCRIPTION | ||
| 122 | |||
| 123 | NetBackup's command line utility B<bpcoverage> provides most of the fodder | ||
| 124 | for this script. However, by pulling in information on all the policies | ||
| 125 | of which the list of hosts are members a more complete picture can be drawn. | ||
| 126 | |||
| 127 | By default all file-systems on each host are listed along with all policies that | ||
| 128 | explicitly reference them. Inactive policies are shown in parentheses. | ||
| 129 | |||
| 130 | Policies which apply to the client but do not reference a particular file-system | ||
| 131 | are listed separately. These could be policies associated with database extension | ||
| 132 | agents, or simply policies with file-lists with entries starting somewhere below | ||
| 133 | any file-system mount-points. | ||
| 134 | |||
| 135 | For Windows based hosts substitute the concept of mount-point with drive-letter. Note that | ||
| 136 | NetBackup is very strict about wanting the drive-letter references in the policy file-list | ||
| 137 | in upper case, with the colon but without a leading back-slash. | ||
| 138 | |||
| 139 | Without any hostnames, coverage.pl will list coverage information on all | ||
| 140 | clients known to the master server. | ||
| 141 | |||
| 142 | =head1 OPTIONS | ||
| 143 | |||
| 144 | =item L<-c|-c> | ||
| 145 | |||
| 146 | Only list file-systems that are covered. | ||
| 147 | |||
| 148 | =item L<-u|-u> | ||
| 149 | |||
| 150 | Only list file-systems that are uncovered. | ||
| 151 | |||
| 152 | =item L<-x|-x> | ||
| 153 | |||
| 154 | Produce output in XML format | ||
| 155 | |||
| 156 | =over 4 | ||
| 157 | |||
| 158 | =back | ||
| 159 | |||
| 160 | =head1 AUTHOR | ||
| 161 | |||
| 162 | Winkeler, Paul pwinkeler@pbnj-solutions.com | ||
| 163 | |||
| 164 | =head1 COPYRIGHT | ||
| 165 | |||
| 166 | Copyright (C) 2002 Paul Winkeler | ||
| 167 | |||
| 168 | =cut |