From 3a8c8e86a8f93972a7c87648e13b3df25347d920 Mon Sep 17 00:00:00 2001 From: hjp Date: Sat, 24 Apr 2010 20:23:58 +0000 Subject: [PATCH] estimate free space by inodes, too. --- scripts/backup | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; } }