Improve logging and documentation of backup device selection

This commit is contained in:
hjp 2020-07-18 08:49:56 +00:00
parent f26d6b6640
commit 25fec312b0
1 changed files with 8 additions and 4 deletions

View File

@ -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) {