2 # Copyright (c) 2010 Zmanda Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use lib '@amperldir@';
24 use Amanda::Config qw( :init :getconf );
26 use Amanda::DB::Catalog;
34 Usage: $0 [[--config] CONFIG] [--hostwidth width] [--diskwidth width]
35 [-skipmissed] [--last] [--num0] [--togo0] [--verbose]
37 This script generates to standard output an overview of the filesystems
38 dumped over time and the type of dump done on a particular day, such as
39 a full dump, or an incremental, or if the dump failed.
41 You may override the default configuration `@DEFAULT_CONFIG@' by using
42 the --config command line option. On larger installations, this script
43 will take a while to run. In this case, run it with --verbose to see
49 # overrideable defaults
50 my $opt_config = undef;
51 my $opt_hostwidth = 8;
52 my $opt_diskwidth = 20;
53 my $opt_skipmissed = 0;
59 GetOptions('config=s' => \$opt_config,
60 'hostwidth=i' => \$opt_hostwidth,
61 'diskwidth=i' => \$opt_diskwidth,
62 'skipmissed' => \$opt_skipmissed,
65 'togo0' => \$opt_togo0,
66 'verbose' => \$opt_verbose)
70 $opt_config = $ARGV[0];
75 #Initialize configuration
76 config_init($CONFIG_INIT_EXPLICIT_NAME, $opt_config);
77 my ($cfgerr_level, @cfgerr_errors) = config_errors();
78 if ($cfgerr_level >= $CFGERR_WARNINGS) {
79 config_print_errors();
80 if ($cfgerr_level >= $CFGERR_ERRORS) {
81 die("errors processing config file");
86 $cfgerr_level = Amanda::Disklist::read_disklist();
87 die("Config errors") if ($cfgerr_level >= $CFGERR_WARNINGS);
90 foreach my $dle (Amanda::Disklist::all_disks()) {
91 $disks{$dle->{"host"}->{"hostname"}}{$dle->{"name"}}++;
97 my ($date, $host, $disk);
99 print STDERR "Processing $opt_config dumps\n";
100 foreach my $dump (Amanda::DB::Catalog::sort_dumps(['hostname','diskname','write_timestamp'],Amanda::DB::Catalog::get_dumps())) {
101 $host = $dump->{"hostname"};
102 $disk = $dump->{"diskname"};
103 $date = substr($dump->{"dump_timestamp"},0,8);
105 if (defined $disks{$host}{$disk}) {
106 defined($level{$host}{$disk}{$date}) or
107 $level{$host}{$disk}{$date} = '';
108 $level{$host}{$disk}{$date} .= ($dump->{"status"} eq 'OK') ? $dump->{"level"} : 'E';
113 # Process the status to arrive at a "last" status
115 for $host (sort keys %disks) {
116 for $disk (sort keys %{$disks{$host}}) {
117 $level{$host}{$disk}{"0000LAST"} = '';
118 for $date (sort keys %dates) {
119 next unless defined($level{$host}{$disk}{$date});
120 if ($level{$host}{$disk}{$date} eq "E"
121 && $level{$host}{$disk}{"0000LAST"} =~ /^\d/ ) {
122 $level{$host}{$disk}{"0000LAST"} .= $level{$host}{$disk}{$date};
124 $level{$host}{$disk}{"0000LAST"} = $level{$host}{$disk}{$date};
131 # Number of level 0 backups
133 for $host (sort keys %disks) {
134 for $disk (sort keys %{$disks{$host}}) {
135 $level{$host}{$disk}{'0000NML0'} = 0;
136 for $date (sort keys %dates) {
137 if (defined($level{$host}{$disk}{$date})
138 && $level{$host}{$disk}{$date} =~ /0/) {
139 $level{$host}{$disk}{'0000NML0'} += 1;
146 # Runs to the last level 0
148 for $host (sort keys %disks) {
149 for $disk (sort keys %{$disks{$host}}) {
150 $level{$host}{$disk}{'0000TOGO'} = 0;
152 for $date (sort keys %dates) {
153 if (defined($level{$host}{$disk}{$date})
154 && $level{$host}{$disk}{$date} =~ /0/) {
155 $level{$host}{$disk}{'0000TOGO'} = $togo;
163 unless ($opt_skipmissed)
164 # touch all the dates just in case whole days were missed.
166 my ($start, $finish) =
168 my($y,$m,$d) = /(....)(..)(..)/;
169 POSIX::mktime(0,0,0,$d,$m-1,$y-1900);
170 } (sort keys %dates)[0,-1];
172 # Special case of only one date
173 if (defined($finish)) {
174 while ($start < $finish) {
175 my @l = localtime $start;
176 $dates{sprintf("%d%02d%02d", 1900+$l[5], $l[4]+1, $l[3])}++;
182 #Add the "last" entry
183 $dates{"0000LAST"}=1 if ($opt_last);
185 #Add the "Number of Level 0s" entry
186 $dates{"0000NML0"}=1 if ($opt_num0);
188 #Add the "Runs to go" entry
189 $dates{"0000TOGO"}=1 if ($opt_togo0);
194 my ($host, $disk, @cols) = @_;
195 $host = substr($host, 0, $opt_hostwidth);
196 $disk = substr($disk, 0, $opt_diskwidth);
198 sprintf("%-0${opt_hostwidth}s %-0${opt_diskwidth}s ", $host, $disk) .
199 join(" ", map(sprintf("%-2s ", $_), @cols)) .
204 my ($host, $disk, $date) = @_;
205 my $levels = $level{$host}{$disk}{$date};
207 # no dumps on this date
208 $levels = '-' unless defined($levels);
210 return substr($levels, -2);
214 row('', 'date', map((/....(..) .. /x)[0], sort keys %dates));
215 row('host', 'disk', map((/.... .. (..)/x)[0], sort keys %dates));
218 for $host (sort keys %disks) {
219 for $disk (sort keys %{$disks{$host}}) {
221 map(fmt_levels($host, $disk, $_), sort keys %dates));