#!/usr/bin/perl use strict; use warnings; use Data::Dumper; chdir '/backups/pc'; opendir(DIR, '.') || die "can't opendir . $!"; my @dirs = grep { ! /^\./ } readdir(DIR); closedir DIR; my %values; foreach my $dir (@dirs) { open( BACKUPS, "<$dir/backups" ) || do { print "Could not open file /backups/pc/$dir/backups \n"; next; }; my $total_total=0; my $new_total=0; my $num_backups=0; while( ) { my @fields = split( /\t/ ); if( $fields[5] =~ /^\d+$/ && $fields[9] =~ /^\d+$/ ) { # THe total size for this backup $total_total += $fields[5]; # Minus what was already there $total_total -= $fields[7]; # THe new/additional size for this backup $new_total += $fields[9]; $num_backups++; } } close( BACKUPS ); $values{$dir} = { total => $total_total, new => $new_total, num => $num_backups, } } print q{ Total New Size Average New Size Per Backup Backup Name Total Size Number Of Backups }; foreach my $key (sort { $values{$b}->{total} <=> $values{$a}->{total} } keys %values) { # printf( "Backup $key has %20.2d GiB of backups on disk total.\n", ( ($values{$key}->{total}) / 1024 / 1024 / 1024 ) ); my $total_gib=( ($values{$key}->{total}) / 1024 / 1024 / 1024 ); my $new_gib=( ($values{$key}->{new}) / 1024 / 1024 / 1024 ); my $num_backups=$values{$key}->{num}; my $avg_new_mib=( ( ($values{$key}->{new}) / $num_backups ) / 1024 / 1024 / 1024 ); format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @####.## GiB @####.## GiB @## @####.#### GiB $key, $total_gib, $new_gib, $num_backups, $avg_new_mib . write; }