From 25fec312b0f5101fa9f1911955c4988f4df35f4b Mon Sep 17 00:00:00 2001 From: hjp Date: Sat, 18 Jul 2020 08:49:56 +0000 Subject: [PATCH] Improve logging and documentation of backup device selection --- scripts/backup | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/backup b/scripts/backup index 76d788a..6530d47 100755 --- a/scripts/backup +++ b/scripts/backup @@ -63,9 +63,10 @@ for (glob("/backup/*")) { } -# find the backup dir with the most free space available. -# other strategies are possible, like round robin, or daily, weekly, -# etc. backups. +# Choose a random backup directory. +# The directories are weighted by free space (e.g, if we have two +# directories with 3 TB and 2 TB free space, then their chances of being +# chosen are 60% and 40%). my @backup_dirs = map { $_ = $1 if m{(.*)/.*}; # basedir and detaint @@ -82,7 +83,10 @@ my @backup_dirs = map { my $sum_free = 0; $sum_free += $_->[1] for (@backup_dirs); $ca->log(3, "total free est. $sum_free bytes"); -my $rnd = rand() * $sum_free; +my $rnd = rand(); +$ca->log(3, "random (raw) = $rnd"); +$rnd *= $sum_free; +$ca->log(3, "random (scaled) = $rnd"); my $count_free = 0; my $backup_dir; for(@backup_dirs) {