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'
17 Usage: $0 [[-config] CONFIG] [-hostwidth width] [-diskwidth width] [-skipmissed] [-last] [-num0] [-togo0] [-verbose]
19 This script generates to standard output an overview of the filesystems
20 dumped over time and the type of dump done on a particular day, such as
21 a full dump, or an incremental, or if the dump failed.
23 You may override the default configuration `@DEFAULT_CONFIG@' by using
24 the -config command line option. On larger installations, this script
25 will take a while to run. In this case, run it with --verbose to see
31 # Default paths for this installation of Amanda.
32 my $prefix='@prefix@';
33 $prefix=$prefix; # avoid warnings about possible typo
34 my $exec_prefix="@exec_prefix@";
35 $exec_prefix=$exec_prefix; # ditto
36 my $libexecdir="@libexecdir@";
37 my $sbindir="@sbindir@";
39 # The directory where configurations can be found.
40 my $confdir="@CONFIG_DIR@";
42 # The default configuration.
43 my $config="@DEFAULT_CONFIG@";
45 # Get the version suffix.
46 my $USE_VERSION_SUFFIXES = '@USE_VERSION_SUFFIXES@';
48 if ( $USE_VERSION_SUFFIXES =~ /^yes$/i ) {
52 my $amadmin = "$sbindir/amadmin$suf";
54 # overrideable defaults
55 my $opt_config = "$config";
56 my $opt_hostwidth = 8;
57 my $opt_diskwidth = 20;
58 my $opt_skipmissed = 0;
64 GetOptions('config=s' => \$opt_config,
65 'hostwidth=i' => \$opt_hostwidth,
66 'diskwidth=i' => \$opt_diskwidth,
67 'skipmissed' => \$opt_skipmissed,
70 'togo0' => \$opt_togo0,
71 'verbose' => \$opt_verbose)
75 $opt_config = $ARGV[0];
81 -d "$confdir/$opt_config" or
82 die "$0: directory `$confdir/$opt_config' does not exist.\n";
89 print STDERR "Running $amadmin $opt_config disklist\n";
90 my $dlfh = new FileHandle "$amadmin $opt_config disklist|" or
91 die "$0: error in opening `$amadmin $opt_config disklist' pipe: $!\n";
94 ($host, $disk) = m/ host (.*?):.* disk (.*?):/s;
96 $disks{$host}{$disk}++;
101 die "$0: error in closing `$amadmin $opt_config disklist|' pipe: $!\n";
107 my ($date, $tape, $file, $status);
109 print STDERR "Running $amadmin $opt_config find\n";
110 my $fh = new FileHandle "$amadmin $opt_config find|" or
111 die "$0: error in opening `$amadmin $opt_config find' pipe: $!\n";
115 next if /found Amanda directory/;
116 next if /skipping cruft directory/;
118 ($date, $host, $disk, $level, $tape, $file, $status) = split ' ', $_;
119 next if $date eq 'date';
120 next if $date eq 'Warning:';
121 next if $date eq 'Scanning';
123 if ($date =~ /^\d\d\d\d-\d\d-\d\d$/) {
124 defined($level{$host}{$disk}{$date}) or
125 $level{$host}{$disk}{$date} = '';
126 $level{$host}{$disk}{$date} .= ($status eq 'OK') ? $level : 'E';
130 print "bad date $date in $_\n";
134 die "$0: error in closing `$amadmin $opt_config find|' pipe: $!\n";
136 # Process the status to arrive at a "last" status
138 for $host (sort keys %disks) {
139 for $disk (sort keys %{$disks{$host}}) {
140 $level{$host}{$disk}{"0000-LA-ST"} = '';
141 for $date (sort keys %dates) {
142 if ($level{$host}{$disk}{$date} eq "E"
143 && $level{$host}{$disk}{"0000-LA-ST"} =~ /^\d/ ) {
144 $level{$host}{$disk}{"0000-LA-ST"} .= $level{$host}{$disk}{$date};
145 } elsif ($level{$host}{$disk}{$date} eq "") {
146 $level{$host}{$disk}{"0000-LA-ST"} =~ s/E//;
148 $level{$host}{$disk}{"0000-LA-ST"} = $level{$host}{$disk}{$date};
155 # Number of level 0 backups
157 for $host (sort keys %disks) {
158 for $disk (sort keys %{$disks{$host}}) {
159 $level{$host}{$disk}{'0000-NM-L0'} = 0;
160 for $date (sort keys %dates) {
161 if ($level{$host}{$disk}{$date} =~ /0/) {
162 $level{$host}{$disk}{'0000-NM-L0'} += 1;
169 # Runs to the last level 0
171 for $host (sort keys %disks) {
172 for $disk (sort keys %{$disks{$host}}) {
173 $level{$host}{$disk}{'0000-TO-GO'} = 0;
175 for $date (sort keys %dates) {
176 if ($level{$host}{$disk}{$date} =~ /0/) {
177 $level{$host}{$disk}{'0000-TO-GO'} = $togo;
185 unless ($opt_skipmissed)
186 # touch all the dates just in case whole days were missed.
188 my ($start, $finish) =
190 my($y,$m,$d) = split /-/, $_;
191 POSIX::mktime(0,0,0,$d,$m-1,$y-1900);
192 } (sort keys %dates)[0,-1];
194 while ($start < $finish) {
195 my @l = localtime $start;
196 $dates{sprintf("%d-%02d-%02d", 1900+$l[5], $l[4]+1, $l[3])}++;
201 #Add the "last" entry
202 $dates{"0000-LA-ST"}=1 if ($opt_last);
204 #Add the "Number of Level 0s" entry
205 $dates{"0000-NM-L0"}=1 if ($opt_num0);
207 #Add the "Runs to go" entry
208 $dates{"0000-TO-GO"}=1 if ($opt_togo0);
212 my $top_format = "format TOP =\n\n" .
213 sprintf("%-0${opt_hostwidth}s %-0${opt_diskwidth}s ", '', 'date') .
214 join(' ', map((split(/-/, $_))[1], sort keys %dates)) . "\n" .
215 sprintf("%-0${opt_hostwidth}s %-0${opt_diskwidth}s ", 'host', 'disk') .
216 join(' ', map((split(/-/, $_))[2], sort keys %dates)) . "\n" .
219 my $out_format = "format STDOUT =\n" .
220 "@" . "<" x ($opt_hostwidth - 1) . ' ' .
221 "@" . "<" x ($opt_diskwidth - 1) . ' ' .
222 '@> ' x scalar(keys %dates) . "\n" .
223 join(', ', '$host', '$disk',
224 map("substr(\$level{\$host}{\$disk}{'$_'},-2)", sort keys %dates)) . "\n" .
233 for $host (sort keys %disks) {
234 for $disk (sort keys %{$disks{$host}}) {