3 @snapshots=`zfs list -t snapshot`;
7 $giga = 1024 * 1024 * 1024;
13 if($size > ($giga)) { $size = $size / $giga; $size = sprintf("%2.2fG",$size); }
14 elsif($size > ($mega)) { $size = int($size / $mega); $size = "$size"."M"; }
15 elsif($size > ($kilo)) { $size = int($size / $kilo); $size = "$size"."K"; }
19 foreach $snapshot (@snapshots)
22 if($snapshot =~ /(\S+)\@(\S+)\s+(\S+)\s+/) {
25 if(length($filesystem) > $maxlen) { $maxlen = length($filesystem); }
26 if($size =~ /k/i) { $size = $size * $kilo; }
27 if($size =~ /m/i) { $size = $size * $mega; }
28 if($size =~ /g/i) { $size = $size * $giga; }
29 $totals{$filesystem}{size} += $size;
30 $totals{$filesystem}{snapshots}++;
35 printf "%-${maxlen}s %-15s %-10s\n","ZFS Filesystem","Snapshots Size","Num Snapshots";
36 printf "%-${maxlen}s %-15s %-10s\n","--","--","--";
37 foreach $key (sort keys %totals)
39 $size = $totals{$key}{size};
41 $total_snapshots += $totals{$key}{snapshots};
42 $size = &adjust_size($size);
43 printf "%-${maxlen}s %-15s %-10s\n", $key, $size, $totals{$key}{snapshots};
46 $total_size = &adjust_size($total_size);
47 printf "%-${maxlen}s %-15s %-10s\n","--","--","--";
48 printf "%-${maxlen}s %-15s %-10s\n","Total Snapshots",$total_size,$total_snapshots;