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'
16 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
17 $ENV{'PATH'} = "/usr/bin:/usr/sbin:/sbin:/bin";
21 Usage: $0 [[-config] CONFIG] [-hostwidth width] [-diskwidth width] [-skipmissed] [-last] [-num0] [-togo0] [-verbose]
23 This script generates to standard output an overview of the filesystems
24 dumped over time and the type of dump done on a particular day, such as
25 a full dump, or an incremental, or if the dump failed.
27 You may override the default configuration `@DEFAULT_CONFIG@' by using
28 the -config command line option. On larger installations, this script
29 will take a while to run. In this case, run it with --verbose to see
35 # Default paths for this installation of Amanda.
36 my $prefix='@prefix@';
37 $prefix=$prefix; # avoid warnings about possible typo
38 my $exec_prefix="@exec_prefix@";
39 $exec_prefix=$exec_prefix; # ditto
40 my $amlibexecdir="@amlibexecdir@";
41 my $sbindir="@sbindir@";
43 # The directory where configurations can be found.
44 my $confdir="@CONFIG_DIR@";
46 # The default configuration.
47 my $config="@DEFAULT_CONFIG@";
49 my $amadmin = "$sbindir/amadmin";
51 # overrideable defaults
52 my $opt_config = "$config";
53 my $opt_hostwidth = 8;
54 my $opt_diskwidth = 20;
55 my $opt_skipmissed = 0;
61 GetOptions('config=s' => \$opt_config,
62 'hostwidth=i' => \$opt_hostwidth,
63 'diskwidth=i' => \$opt_diskwidth,
64 'skipmissed' => \$opt_skipmissed,
67 'togo0' => \$opt_togo0,
68 'verbose' => \$opt_verbose)
72 $opt_config = $ARGV[0];
78 #untaint user input $ARGV[0]
80 if ($opt_config =~ /^([\w.-]+)$/) { # $1 is untainted
83 die "filename '$opt_config' has invalid characters.\n";
87 -d "$confdir/$opt_config" or
88 die "$0: directory `$confdir/$opt_config' does not exist.\n";
95 print STDERR "Running $amadmin $opt_config disklist\n";
96 my $dlfh = new FileHandle "$amadmin $opt_config disklist|" or
97 die "$0: error in opening `$amadmin $opt_config disklist' pipe: $!\n";
100 ($host, $disk) = m/ host (.*?):\n.* disk (.*?):\n.*strategy (STANDARD|NOFULL|NOINC|HANOI|INCRONLY).*ignore NO/ms;
102 $disks{$host}{$disk}++;
107 die "$0: error in closing `$amadmin $opt_config disklist|' pipe: $!\n";
113 my ($date, $tape, $file, $status);
115 print STDERR "Running $amadmin $opt_config find\n";
116 my $fh = new FileHandle "$amadmin $opt_config find|" or
117 die "$0: error in opening `$amadmin $opt_config find' pipe: $!\n";
121 next if /found Amanda directory/;
122 next if /skipping cruft directory/;
125 ($date, $time, $host, $disk, $level, $tape, $file, $part, $status, $remaining) = shellwords($_);
127 next if $date eq 'date';
128 next if $date eq 'Warning:';
129 next if $date eq 'Scanning';
132 $status .= " " . $remaining;
133 if($time !~/^\d\d:\d\d:\d\d$/) {
142 next if ($part != 1);
144 if ($date =~ /^\d\d\d\d-\d\d-\d\d$/) {
145 if(defined $disks{$host}{$disk}) {
146 defined($level{$host}{$disk}{$date}) or
147 $level{$host}{$disk}{$date} = '';
148 $level{$host}{$disk}{$date} .= ($status eq 'OK') ? $level : 'E';
153 print "bad date $date in $_\n";
157 die "$0: error in closing `$amadmin $opt_config find|' pipe: $!\n";
159 # Process the status to arrive at a "last" status
161 for $host (sort keys %disks) {
162 for $disk (sort keys %{$disks{$host}}) {
163 $level{$host}{$disk}{"0000-LA-ST"} = '';
164 for $date (sort keys %dates) {
165 if ($level{$host}{$disk}{$date} eq "E"
166 && $level{$host}{$disk}{"0000-LA-ST"} =~ /^\d/ ) {
167 $level{$host}{$disk}{"0000-LA-ST"} .= $level{$host}{$disk}{$date};
168 } elsif ($level{$host}{$disk}{$date} eq "") {
169 $level{$host}{$disk}{"0000-LA-ST"} =~ s/E//;
171 $level{$host}{$disk}{"0000-LA-ST"} = $level{$host}{$disk}{$date};
178 # Number of level 0 backups
180 for $host (sort keys %disks) {
181 for $disk (sort keys %{$disks{$host}}) {
182 $level{$host}{$disk}{'0000-NM-L0'} = 0;
183 for $date (sort keys %dates) {
184 if ($level{$host}{$disk}{$date} =~ /0/) {
185 $level{$host}{$disk}{'0000-NM-L0'} += 1;
192 # Runs to the last level 0
194 for $host (sort keys %disks) {
195 for $disk (sort keys %{$disks{$host}}) {
196 $level{$host}{$disk}{'0000-TO-GO'} = 0;
198 for $date (sort keys %dates) {
199 if ($level{$host}{$disk}{$date} =~ /0/) {
200 $level{$host}{$disk}{'0000-TO-GO'} = $togo;
208 unless ($opt_skipmissed)
209 # touch all the dates just in case whole days were missed.
211 my ($start, $finish) =
213 my($y,$m,$d) = split /-/, $_;
214 POSIX::mktime(0,0,0,$d,$m-1,$y-1900);
215 } (sort keys %dates)[0,-1];
217 while ($start < $finish) {
218 my @l = localtime $start;
219 $dates{sprintf("%d-%02d-%02d", 1900+$l[5], $l[4]+1, $l[3])}++;
224 #Add the "last" entry
225 $dates{"0000-LA-ST"}=1 if ($opt_last);
227 #Add the "Number of Level 0s" entry
228 $dates{"0000-NM-L0"}=1 if ($opt_num0);
230 #Add the "Runs to go" entry
231 $dates{"0000-TO-GO"}=1 if ($opt_togo0);
235 my $top_format = "format TOP =\n\n" .
236 sprintf("%-0${opt_hostwidth}s %-0${opt_diskwidth}s ", '', 'date') .
237 join(' ', map((split(/-/, $_))[1], sort keys %dates)) . "\n" .
238 sprintf("%-0${opt_hostwidth}s %-0${opt_diskwidth}s ", 'host', 'disk') .
239 join(' ', map((split(/-/, $_))[2], sort keys %dates)) . "\n" .
242 my $out_format = "format STDOUT =\n" .
243 "@" . "<" x ($opt_hostwidth - 1) . ' ' .
244 "@" . "<" x ($opt_diskwidth - 1) . ' ' .
245 '@> ' x scalar(keys %dates) . "\n" .
246 join(', ', '$host', '$disk',
247 map("substr(\$level{\$host}{\$disk}{'$_'},-2)", sort keys %dates)) . "\n" .
256 for $host (sort keys %disks) {
257 for $disk (sort keys %{$disks{$host}}) {