3 # Catch for sh/csh on systems without #! ability.
4 eval '(exit $?0)' && eval 'exec @PERL@ -S $0 ${1+"$@"}'
5 & eval 'exec @PERL@ -S $0 $argv:q'
18 Usage: $0 [[-config] CONFIG] [-hostwidth width] [-diskwidth width] [-skipmissed] [-last] [-num0] [-togo0] [-verbose]
20 This script generates to standard output an overview of the filesystems
21 dumped over time and the type of dump done on a particular day, such as
22 a full dump, or an incremental, or if the dump failed.
24 You may override the default configuration `@DEFAULT_CONFIG@' by using
25 the -config command line option. On larger installations, this script
26 will take a while to run. In this case, run it with --verbose to see
32 # Default paths for this installation of Amanda.
33 my $prefix='@prefix@';
34 $prefix=$prefix; # avoid warnings about possible typo
35 my $exec_prefix="@exec_prefix@";
36 $exec_prefix=$exec_prefix; # ditto
37 my $libexecdir="@libexecdir@";
38 my $sbindir="@sbindir@";
40 # The directory where configurations can be found.
41 my $confdir="@CONFIG_DIR@";
43 # The default configuration.
44 my $config="@DEFAULT_CONFIG@";
46 # Get the version suffix.
47 my $USE_VERSION_SUFFIXES = '@USE_VERSION_SUFFIXES@';
49 if ( $USE_VERSION_SUFFIXES =~ /^yes$/i ) {
53 my $amadmin = "$sbindir/amadmin$suf";
55 # overrideable defaults
56 my $opt_config = "$config";
57 my $opt_hostwidth = 8;
58 my $opt_diskwidth = 20;
59 my $opt_skipmissed = 0;
65 GetOptions('config=s' => \$opt_config,
66 'hostwidth=i' => \$opt_hostwidth,
67 'diskwidth=i' => \$opt_diskwidth,
68 'skipmissed' => \$opt_skipmissed,
71 'togo0' => \$opt_togo0,
72 'verbose' => \$opt_verbose)
76 $opt_config = $ARGV[0];
82 #untaint user input $ARGV[0]
84 if ($opt_config =~ /^([\w.-]+)$/) { # $1 is untainted
87 die "filename '$opt_config' has invalid characters.\n";
91 -d "$confdir/$opt_config" or
92 die "$0: directory `$confdir/$opt_config' does not exist.\n";
99 print STDERR "Running $amadmin $opt_config disklist\n";
100 my $dlfh = new FileHandle "$amadmin $opt_config disklist|" or
101 die "$0: error in opening `$amadmin $opt_config disklist' pipe: $!\n";
104 ($host, $disk) = m/ host (.*?):.* disk (.*?):/s;
106 $disks{$host}{$disk}++;
111 die "$0: error in closing `$amadmin $opt_config disklist|' pipe: $!\n";
117 my ($date, $tape, $file, $status);
119 print STDERR "Running $amadmin $opt_config find\n";
120 my $fh = new FileHandle "$amadmin $opt_config find|" or
121 die "$0: error in opening `$amadmin $opt_config find' pipe: $!\n";
126 next if /found Amanda directory/;
127 next if /skipping cruft directory/;
129 ($date, $host, $disk, $level, $tape, $file, $part, $status) = quotewords(" ", 0, $_);
130 next if $date eq 'date';
131 next if $date eq 'Warning:';
132 next if $date eq 'Scanning';
134 if ($date =~ /^\d\d\d\d-\d\d-\d\d$/) {
135 defined($level{$host}{$disk}{$date}) or
136 $level{$host}{$disk}{$date} = '';
137 $level{$host}{$disk}{$date} .= ($status eq 'OK') ? $level : 'E';
141 print "bad date $date in $_\n";
145 die "$0: error in closing `$amadmin $opt_config find|' pipe: $!\n";
147 # Process the status to arrive at a "last" status
149 for $host (sort keys %disks) {
150 for $disk (sort keys %{$disks{$host}}) {
151 $level{$host}{$disk}{"0000-LA-ST"} = '';
152 for $date (sort keys %dates) {
153 if ($level{$host}{$disk}{$date} eq "E"
154 && $level{$host}{$disk}{"0000-LA-ST"} =~ /^\d/ ) {
155 $level{$host}{$disk}{"0000-LA-ST"} .= $level{$host}{$disk}{$date};
156 } elsif ($level{$host}{$disk}{$date} eq "") {
157 $level{$host}{$disk}{"0000-LA-ST"} =~ s/E//;
159 $level{$host}{$disk}{"0000-LA-ST"} = $level{$host}{$disk}{$date};
166 # Number of level 0 backups
168 for $host (sort keys %disks) {
169 for $disk (sort keys %{$disks{$host}}) {
170 $level{$host}{$disk}{'0000-NM-L0'} = 0;
171 for $date (sort keys %dates) {
172 if ($level{$host}{$disk}{$date} =~ /0/) {
173 $level{$host}{$disk}{'0000-NM-L0'} += 1;
180 # Runs to the last level 0
182 for $host (sort keys %disks) {
183 for $disk (sort keys %{$disks{$host}}) {
184 $level{$host}{$disk}{'0000-TO-GO'} = 0;
186 for $date (sort keys %dates) {
187 if ($level{$host}{$disk}{$date} =~ /0/) {
188 $level{$host}{$disk}{'0000-TO-GO'} = $togo;
196 unless ($opt_skipmissed)
197 # touch all the dates just in case whole days were missed.
199 my ($start, $finish) =
201 my($y,$m,$d) = split /-/, $_;
202 POSIX::mktime(0,0,0,$d,$m-1,$y-1900);
203 } (sort keys %dates)[0,-1];
205 while ($start < $finish) {
206 my @l = localtime $start;
207 $dates{sprintf("%d-%02d-%02d", 1900+$l[5], $l[4]+1, $l[3])}++;
212 #Add the "last" entry
213 $dates{"0000-LA-ST"}=1 if ($opt_last);
215 #Add the "Number of Level 0s" entry
216 $dates{"0000-NM-L0"}=1 if ($opt_num0);
218 #Add the "Runs to go" entry
219 $dates{"0000-TO-GO"}=1 if ($opt_togo0);
223 my $top_format = "format TOP =\n\n" .
224 sprintf("%-0${opt_hostwidth}s %-0${opt_diskwidth}s ", '', 'date') .
225 join(' ', map((split(/-/, $_))[1], sort keys %dates)) . "\n" .
226 sprintf("%-0${opt_hostwidth}s %-0${opt_diskwidth}s ", 'host', 'disk') .
227 join(' ', map((split(/-/, $_))[2], sort keys %dates)) . "\n" .
230 my $out_format = "format STDOUT =\n" .
231 "@" . "<" x ($opt_hostwidth - 1) . ' ' .
232 "@" . "<" x ($opt_diskwidth - 1) . ' ' .
233 '@> ' x scalar(keys %dates) . "\n" .
234 join(', ', '$host', '$disk',
235 map("substr(\$level{\$host}{\$disk}{'$_'},-2)", sort keys %dates)) . "\n" .
244 for $host (sort keys %disks) {
245 for $disk (sort keys %{$disks{$host}}) {