2006-11-20 00:00:08 +01:00
|
|
|
#!/usr/bin/perl -T
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use Simba::CA;
|
2007-11-15 21:15:56 +01:00
|
|
|
use POSIX qw(strftime);
|
2008-03-21 12:12:42 +01:00
|
|
|
use Getopt::Long;
|
2008-07-15 23:17:14 +02:00
|
|
|
use Filesys::Statvfs;
|
2008-03-21 12:12:42 +01:00
|
|
|
|
|
|
|
my @filesets;
|
|
|
|
|
|
|
|
GetOptions('filesets=i' => \@filesets);
|
|
|
|
@filesets = split(/,/,join(',',@filesets));
|
2006-11-20 00:00:08 +01:00
|
|
|
|
|
|
|
$ENV{PATH} = "/usr/bin";
|
|
|
|
|
2007-11-15 21:15:56 +01:00
|
|
|
my $now = strftime('%Y-%m-%dT%H:%M:%S', localtime());
|
|
|
|
open(my $log, '>>', '/var/log/simba/ca.log.' . $now);
|
2007-06-18 03:00:29 +02:00
|
|
|
$log->autoflush(1);
|
2007-06-18 21:42:08 +02:00
|
|
|
|
|
|
|
my $ca = Simba::CA->new({
|
|
|
|
dbi_file => $ENV{SIMBA_DB_CONN} || "$ENV{HOME}/.dbi/simba",
|
|
|
|
fh_log => $log,
|
2008-03-21 12:12:42 +01:00
|
|
|
(@filesets ? ( filesets => \@filesets ) : ()),
|
2007-06-18 21:42:08 +02:00
|
|
|
});
|
2008-07-13 22:01:25 +02:00
|
|
|
$ca->log_level(9);
|
2006-11-20 00:00:08 +01:00
|
|
|
|
2008-07-15 23:17:14 +02:00
|
|
|
# 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");
|
2009-06-28 22:21:14 +02:00
|
|
|
@backup_dirs = sort { $b->[1] <=> $a->[1] } @backup_dirs;
|
|
|
|
unless (@backup_dirs) {
|
|
|
|
$ca->log(0, "no backup directory found");
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-07-15 23:17:14 +02:00
|
|
|
$ca->basedir($backup_dirs[0][0]);
|
|
|
|
|
2006-11-20 00:00:08 +01:00
|
|
|
$ca->run();
|