diff --git a/scripts/backup b/scripts/backup index 5e07748..a39b788 100755 --- a/scripts/backup +++ b/scripts/backup @@ -53,7 +53,11 @@ my @backup_dirs = map { my($bsize, $frsize, $blocks, $bfree, $bavail, $files, $ffree, $favail, $flag, $namemax) = statvfs($_); - [ $_, $bsize * $bavail ] + my $available_bytes = $bsize * $bavail; + my $avg_file_size = $bavail * ($blocks - $bfree) / ($files - $ffree); + my $available_bytes_by_files = $avg_file_size * $favail; + $available_bytes = $available_bytes_by_files if $available_bytes_by_files < $available_bytes; + [ $_, $available_bytes ] } glob("/backup/*/active"); my $sum_free = 0; $sum_free += $_->[1] for (@backup_dirs); @@ -62,8 +66,10 @@ my $count_free = 0; my $backup_dir; for(@backup_dirs) { $count_free += $_->[1]; + $ca->log(3, "considering base $_->[0] (est. $_->[1] bytes)\n"); if ($count_free >= $rnd) { $backup_dir = $_->[0]; + $ca->log(3, "using base $_->[0]\n"); last; } }