unless defined $c->{$required} && $c->{$required} ne '';
}
+ # set some defaults.
+ for my $type (qw/days weeks/) {
+ $c->{'save'}{$type} ||= 0;
+ }
+ $c->{'save'}{'hours'} ||= 1;
+
+ # To ensure we have enough days to take weekly snapshots, make sure
+ # we have enough.
+ if ($c->{'save'}{'weeks'} > 0 && $c->{'save'}{'days'} < 7) {
+ $c->{'save'}{'days'} = 7;
+ }
+
$c->{'cp'} ||= "cp -alf";
$c->{'weekdir'} = "$c->{'backuproot'}/$c->{'hostid'}/weekly";
$c->{'daydir'} = "$c->{'backuproot'}/$c->{'hostid'}/daily";
sub doweek {
return
- if defined $c->{'save'}{'weeks'} && $c->{'save'}{'weeks'} == 0;
+ if $c->{'save'}{'weeks'} == 0;
if (test("-d $c->{'daydir'}/$c->{'lweek'}")) {
run_and_check("mv $c->{'daydir'}/$c->{'lweek'} $c->{'weekdir'}")
sub doday {
return
- if defined $c->{'save'}{'days'} && $c->{'save'}{'days'} == 0;
+ if $c->{'save'}{'days'} == 0;
if (test("-d $c->{'hourdir'}/$c->{'lday'}")) {
run_and_check("mv $c->{'hourdir'}/$c->{'lday'} $c->{'daydir'}");
}
sub docleanup {
- $c->{'save'}{'hours'} ||= 1;
-
- my @hours = split("\n", run_and_return("ls -t $c->{'hourdir'}"));
-
- my $count = 0;
- for my $hour (@hours) {
- $count++;
-
- if ($count > $c->{'save'}{'hours'}) {
- run_and_check("rm -Rf $c->{'hourdir'}/$hour");
- }
+ for my $type (qw/day hour week/) {
+ _docleanup($type};
}
+}
- if ($c->{'save'}{'weeks'} > 0 && $c->{'save'}{'days'} < 7) {
- $c->{'save'}{'days'} = 7;
- }
-
- my @days = split("\n", run_and_return("ls -t $c->{'daydir'}"));
-
- $count = 0;
- for my $day (@days) {
- $count++;
-
- if ($count > $c->{'save'}{'days'}) {
- run_and_check("rm -Rf $c->{'daydir'}/$day");
- }
- }
+sub _docleanup {
+ my $type = shift;
+ my $dir = $type . "dir";
- my @weeks = split("\n", run_and_return("ls -t $c->{'weekdir'}"));
+ my @snapshots = split("\n", run_and_return("ls -t $c->{$dir}"));
- $count = 0;
- for my $week (@weeks) {
+ my $count = 0;
+ for my $snapshot (@snapshots) {
$count++;
- if ($count > $c->{'save'}{'weeks'}) {
- run_and_check("rm -Rf $c->{'weekdir'}/$week");
+ if ($count > $c->{'save'}{$type}) {
+ run_and_check("rm -Rf $c->{$dir}/$snapshot");
}
}
}
-
-
# Perform a test, either via ssh or using a local perl check
sub test {
my ($test) = shift;