script/history.pl untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 95 CC 2 SCAR 12.8
CC
2
Cov
0%
dispInterval
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.6
1 #!/usr/local/bin/perl -w
2  
3 use strict;
4  
5 use Getopt::Std;
6  
7 use NBU;
8  
9 my %opts;
10 getopts('?vnbadfRl:c:', \%opts);
11  
12 if ($opts{'?'}) {
13 print <<EOT;
14 history.pl [-a] [-f] [-R [-l <levels>]] [-c <class-regexp>] <client-name>
15 EOT
16 exit 0;
17 }
18  
19 sub dispInterval {
20 my $i = shift;
21  
22 return "--:--:--" if (!defined($i));
23  
24 my $seconds = $i % 60; $i = int($i / 60);
25 my $minutes = $i % 60;
26 my $hours = int($i / 60);
27  
28 my $fmt = sprintf("%02d", $seconds);
29 $fmt = sprintf("%02d:", $minutes).$fmt;
30 $fmt = sprintf("%02d:", $hours).$fmt;
31 return $fmt;
32 }
33  
34 #
35 # Activate internal debugging if -d was specified
36 NBU->debug($opts{'d'});
37  
38 #
39 # The remaining arguments are the names of hosts whose image history
40 # is to be analyzed
41 push @ARGV, NBU->me->name if (@ARGV == 0);
42 my $displayHostName = ($#ARGV > 0);
43 for my $clientName (@ARGV) {
44  
45 print "$clientName\:\n" if ($displayHostName);
46 my $h = NBU::Host->new($clientName);
47  
48 my $n = 0;
49 my %found;
50 foreach my $image (sort { $b->ctime <=> $a->ctime} $h->images) {
51 $n++;
52  
53 if ($opts{'c'}) {
54 my $classPattern = $opts{'c'};
55 next unless ($image->class->name =~ /$classPattern/);
56 }
57 my $key = $image->class->name."/".($opts{'n'} ? $image->schedule->name : $image->schedule->type);
58 next if (!$opts{'a'} && exists($found{$key}));
59  
60 $found{$key} += 1;
61  
62 printf("%4u:", $n);
63  
64 my $id = $key;
65 if ($opts{'b'}) {
66 $id .= " (".$image->id.")";
67 }
68  
69 print substr(localtime($image->ctime), 4)." $id";
70 print " wrote ".$image->size if (defined($image->size));
71 print " in ".dispInterval($image->elapsed) if ($opts{'v'});
72 print " Expires ".substr(localtime($image->expires), 4);
73 print "\n";
74 if ($opts{'f'}) {
75 for my $f ($image->fragments) {
76 print " ".$f->number.": File ".$f->fileNumber.", ".$f->size." on ".$f->volume->id." drive ".$f->driveWrittenOn." of ".$f->volume->mmdbHost->name."\n";
77 }
78 }
79 if ($opts{'R'}) {
80 $image->fileRecursionDepth($opts{'l'}) if (defined($opts{'l'}));
81 for my $f ($image->fileList) {
82 print " $f\n";
83 }
84 }
85 }
86 }
87  
88 =head1 NAME
89  
90 history.pl - Display host backup history
91  
92 =head1 SYNOPSIS
93  
94 history.pl [options...] <hostname>
95  
96 =head1 DESCRIPTION
97  
98 Using a variety of NetBackup command line tools, B<history.pl> pulls together a complete history
99 of all images currently in the NetBackup catalog pertaining to the referenced host. By default
100 this listing will show only the most recent run of each policy/schedule combination. The B<-a>
101 option will cause all images to get listed.
102  
103 =head1 OPTIONS
104  
105 =over 4
106  
107 =item L<-a|-a>
108  
109 List all occurrences of each policy/schedule combination rather than just the first one.
110  
111 =item L<-n|-n>
112  
113 For the purposes of determining policy/schedule combinations, the default is to key off
114 each schedule's type. This option will use schedule names instead.
115  
116 =item L<-b|-b>
117  
118 In the image listing, include the backupid of each image. This is useful if you are
119 constructing a restore command line.
120  
121 =item L<-f|-f>
122  
123 For each image the individual fragments are listed out. Note that in environments where
124 storage units limit images to small fragment sizes this output can be quite voluminous. However,
125 this option is a convenient way to get at the list of tapes used by each image.
126  
127 =item L<-R|-R>
128  
129 Recursively list out all the files backed up as part of this image.
130  
131 =item L<-l depth|-ldepth>
132  
133 By default file recursion depth is set to 1. This means that path list entries that explictly
134 start at a depth already greater than 1, will not show at all! Setting the depth to large values
135 will result in very long listings.
136  
137 =item L<-c pattern|-cpattern>
138  
139 The pattern will be applied to each policy name and only the matching policies will be displayed. Note
140 that the (arbitrary) image counter still counts each and every image.
141  
142 =back
143  
144 =head1 SEE ALSO
145  
146 =over 4
147  
148 =item L<toc.pl|toc.pl>
149  
150 =back
151  
152 =head1 AUTHOR
153  
154 Winkeler, Paul pwinkeler@pbnj-solutions.com
155  
156 =head1 COPYRIGHT
157  
158 Copyright (C) 2002 Paul Winkeler
159  
160 =cut