write to random backup device, not the least full

This commit is contained in:
hjp 2010-04-13 21:54:39 +00:00
parent f8856de2c9
commit 4aa78b8530
1 changed files with 15 additions and 4 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/perl -T
#!/usr/bin/perl
use warnings;
use strict;
use Simba::CA;
@ -55,11 +55,22 @@ my @backup_dirs = map {
= statvfs($_);
[ $_, $bsize * $bavail ]
} glob("/backup/*/active");
@backup_dirs = sort { $b->[1] <=> $a->[1] } @backup_dirs;
unless (@backup_dirs) {
my $sum_free = 0;
$sum_free += $_->[1] for (@backup_dirs);
my $rnd = rand() * $sum_free;
my $count_free = 0;
my $backup_dir;
for(@backup_dirs) {
$count_free += $_->[1];
if ($count_free >= $rnd) {
$backup_dir = $_->[0];
last;
}
}
unless ($backup_dir) {
$ca->log(0, "no backup directory found");
exit(1);
}
$ca->basedir($backup_dirs[0][0]);
$ca->basedir($backup_dir);
$ca->run();