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();