| 1 | #!/usr/local/bin/perl -w | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | use Getopt::Std; | ||
| 6 | use Time::Local; | ||
| 7 | |||
| 8 | my %opts; | ||
| 9 | getopts('d?', \%opts); | ||
| 10 | |||
| 11 | use NBU; | ||
| 12 | NBU->debug($opts{'d'}); | ||
| 13 | |||
| 14 | NBU::Image->populate; | ||
| 15 | |||
| 16 | my @l = NBU::Image->list; | ||
| 17 | print "There are $#l images\n"; | ||
| 18 | |||
| 19 | my %retentionTotal; | ||
| 20 | my %retentionVolumes; | ||
| 21 | my %inUse; | ||
| 22 | my $total = 0; | ||
| 23 | for my $image (@l) { | ||
| 24 | next if (!defined($image->size)); | ||
| 25 | |||
| 26 | my $size = $image->size / 1024; | ||
| 27 | |||
| 28 | my $rlc = $image->density.":".$image->retention->level; | ||
| 29 | $retentionTotal{$rlc} += $size; | ||
| 30 | |||
| 31 | # | ||
| 32 | # To ensure we only count each volume once (it may contain many | ||
| 33 | # images) we tag each one. The tag is further qualified with the | ||
| 34 | # volume's retention level and density since occasionally things | ||
| 35 | # change over time and a single volume gets re-used across different | ||
| 36 | # retention levels and/or densities... | ||
| 37 | if (!exists($inUse{$rlc.$image->volume->id})) { | ||
| 38 | if (!exists($retentionVolumes{$rlc})) { | ||
| 39 | $retentionVolumes{$rlc} = 1; | ||
| 40 | } | ||
| 41 | else { | ||
| 42 | $retentionVolumes{$rlc} += 1; | ||
| 43 | } | ||
| 44 | $inUse{$rlc.$image->volume->id} = +1; | ||
| 45 | } | ||
| 46 | $total += $size; | ||
| 47 | } | ||
| 48 | |||
| 49 | for my $l (sort (keys %retentionTotal)) { | ||
| 50 | my $rlt = sprintf("%10.2f", $retentionTotal{$l}/1024); | ||
| 51 | my $rlc = $retentionVolumes{$l}; | ||
| 52 | my ($density, $rl) = split(':', $l); | ||
| 53 | my $r = NBU::Retention->byLevel($rl); | ||
| 54 | print $rlt."Gb at ".$r->description." on $rlc ".$density." volumes\n"; | ||
| 55 | } | ||
| 56 | |||
| 57 | $total = sprintf("%.2f", $total/1024); | ||
| 58 | print "Total size is ${total}Gb\n"; |