From 4aa78b8530a598b334e53c4318c9af2bd542fa9a Mon Sep 17 00:00:00 2001 From: hjp Date: Tue, 13 Apr 2010 21:54:39 +0000 Subject: [PATCH] write to random backup device, not the least full --- scripts/backup | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scripts/backup b/scripts/backup index a590072..5e07748 100755 --- a/scripts/backup +++ b/scripts/backup @@ -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();