#!/usr/bin/perl @snapshots=`zfs list -t snapshot`; $kilo = 1024; $mega = 1024 * 1024; $giga = 1024 * 1024 * 1024; $maxlen = 0; sub adjust_size { my ($size) = @_; if($size > ($giga)) { $size = $size / $giga; $size = sprintf("%2.2fG",$size); } elsif($size > ($mega)) { $size = int($size / $mega); $size = "$size"."M"; } elsif($size > ($kilo)) { $size = int($size / $kilo); $size = "$size"."K"; } return $size; } foreach $snapshot (@snapshots) { chomp($snapshot); if($snapshot =~ /(\S+)\@(\S+)\s+(\S+)\s+/) { $filesystem = $1; $size = $3; if(length($filesystem) > $maxlen) { $maxlen = length($filesystem); } if($size =~ /k/i) { $size = $size * $kilo; } if($size =~ /m/i) { $size = $size * $mega; } if($size =~ /g/i) { $size = $size * $giga; } $totals{$filesystem}{size} += $size; $totals{$filesystem}{snapshots}++; } } $maxlen=$maxlen+2; printf "%-${maxlen}s %-15s %-10s\n","ZFS Filesystem","Snapshots Size","Num Snapshots"; printf "%-${maxlen}s %-15s %-10s\n","--","--","--"; foreach $key (sort keys %totals) { $size = $totals{$key}{size}; $total_size += $size; $total_snapshots += $totals{$key}{snapshots}; $size = &adjust_size($size); printf "%-${maxlen}s %-15s %-10s\n", $key, $size, $totals{$key}{snapshots}; } $total_size = &adjust_size($total_size); printf "%-${maxlen}s %-15s %-10s\n","--","--","--"; printf "%-${maxlen}s %-15s %-10s\n","Total Snapshots",$total_size,$total_snapshots;