From 54c4472a164a5b99a0bf6b64a1721f45675d66c1 Mon Sep 17 00:00:00 2001 From: hjp Date: Tue, 15 Jul 2008 21:17:14 +0000 Subject: [PATCH] deal with several backup dirs. --- backup | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backup b/backup index 72123b8..580111e 100755 --- a/backup +++ b/backup @@ -4,6 +4,7 @@ use strict; use Simba::CA; use POSIX qw(strftime); use Getopt::Long; +use Filesys::Statvfs; my @filesets; @@ -23,4 +24,18 @@ my $ca = Simba::CA->new({ }); $ca->log_level(9); +# find the backup dir with the most free space available. +# other strategies are possible, like round robin, or daily, weekly, +# etc. backups. + +my @backup_dirs = map { + $_ = $1 if m{(.*)/.*}; # basedir and detaint + my($bsize, $frsize, $blocks, $bfree, $bavail, + $files, $ffree, $favail, $flag, $namemax) + = statvfs($_); + [ $_, $bsize * $bavail ] + } glob("/backup/*/active"); +@backup_dirs = sort { $b->[1] <=> $b->[0] } @backup_dirs; +$ca->basedir($backup_dirs[0][0]); + $ca->run();