Skip to content

Commit

Permalink
btrbk: change preserve logic: keep FIRST present of hour/day/... inst…
Browse files Browse the repository at this point in the history
…ead of LAST
  • Loading branch information
digint committed Apr 13, 2016
1 parent 6b07316 commit bd34d9f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
46 changes: 23 additions & 23 deletions btrbk
Original file line number Diff line number Diff line change
Expand Up @@ -2634,11 +2634,11 @@ sub schedule(@)
$href->{preserve} ||= $preserve_latest;
}

my %last_in_delta_hours;
my %last_in_delta_days;
my %first_in_delta_hours;
my %first_in_delta_days;
my %first_in_delta_weeks;
my %last_weekly_in_delta_months;
my %last_monthly_in_delta_years;
my %first_weekly_in_delta_months;
my %first_monthly_in_delta_years;

# filter "preserve all within N days/weeks/..."
foreach my $href (@sorted_schedule) {
Expand All @@ -2657,21 +2657,21 @@ sub schedule(@)
$href->{preserve} ||= "preserve all: $href->{delta_years} years ago" if($href->{delta_years} <= $preserve_all_n);
}
}
$last_in_delta_hours{$href->{delta_hours}} = $href;
$first_in_delta_hours{$href->{delta_hours}} //= $href;
}

# filter hourly, daily, weekly, monthly, yearly
foreach (sort {$b <=> $a} keys %last_in_delta_hours) {
my $href = $last_in_delta_hours{$_} || die;
foreach (sort {$b <=> $a} keys %first_in_delta_hours) {
my $href = $first_in_delta_hours{$_} || die;
if($preserve_hourly && (($preserve_hourly eq 'all') || $href->{delta_hours} <= $preserve_hourly)) {
$href->{preserve} ||= "preserved hourly: last present of hour, $href->{delta_hours} hours ago";
$href->{preserve} ||= "preserved hourly: first present of hour, $href->{delta_hours} hours ago";
}
$last_in_delta_days{$href->{delta_days}} = $href;
$first_in_delta_days{$href->{delta_days}} //= $href;
}
foreach (sort {$b <=> $a} keys %last_in_delta_days) {
my $href = $last_in_delta_days{$_} || die;
foreach (sort {$b <=> $a} keys %first_in_delta_days) {
my $href = $first_in_delta_days{$_} || die;
if($preserve_daily && (($preserve_daily eq 'all') || ($href->{delta_days} <= $preserve_daily))) {
$href->{preserve} ||= "preserved daily: last present of day, $href->{delta_days} days ago";
$href->{preserve} ||= "preserved daily: first present of day, $href->{delta_days} days ago";
}
$first_in_delta_weeks{$href->{delta_weeks}} //= $href;
}
Expand All @@ -2681,19 +2681,19 @@ sub schedule(@)
if($preserve_weekly && (($preserve_weekly eq 'all') || ($href->{delta_weeks} <= $preserve_weekly))) {
$href->{preserve} ||= "preserved weekly: $href->{delta_weeks} weeks ago, $href->{err_days_text}";
}
$last_weekly_in_delta_months{$href->{delta_months}} = $href;
$first_weekly_in_delta_months{$href->{delta_months}} //= $href;
}
foreach (sort {$b <=> $a} keys %last_weekly_in_delta_months) {
my $href = $last_weekly_in_delta_months{$_} || die;
foreach (sort {$b <=> $a} keys %first_weekly_in_delta_months) {
my $href = $first_weekly_in_delta_months{$_} || die;
if($preserve_monthly && (($preserve_monthly eq 'all') || ($href->{delta_months} <= $preserve_monthly))) {
$href->{preserve} ||= "preserved monthly: last present weekly of month $href->{month} ($href->{delta_months} months ago, $href->{err_days_text})";
$href->{preserve} ||= "preserved monthly: first present weekly of month $href->{month} ($href->{delta_months} months ago, $href->{err_days_text})";
}
$last_monthly_in_delta_years{$href->{delta_years}} = $href;
$first_monthly_in_delta_years{$href->{delta_years}} //= $href;
}
foreach (sort {$b <=> $a} keys %last_monthly_in_delta_years) {
my $href = $last_monthly_in_delta_years{$_} || die;
foreach (sort {$b <=> $a} keys %first_monthly_in_delta_years) {
my $href = $first_monthly_in_delta_years{$_} || die;
if($preserve_yearly && (($preserve_yearly eq 'all') || ($href->{delta_years} <= $preserve_yearly))) {
$href->{preserve} ||= "preserved yearly: last present weekly of year $href->{year} ($href->{delta_years} years ago, $href->{err_days_text})";
$href->{preserve} ||= "preserved yearly: first present weekly of year $href->{year} ($href->{delta_years} years ago, $href->{err_days_text})";
}
}

Expand Down Expand Up @@ -2747,13 +2747,13 @@ sub format_preserve_matrix($@)
}
else {
push @out, "preserving all within $preserve->{all_n} $trans{$preserve->{all_q}}" if($preserve->{all_n} && $preserve->{all_q});
push @out, "last present daily for $preserve->{d} days" if($preserve->{d});
push @out, "first present daily for $preserve->{d} days" if($preserve->{d});
unless($preserve->{d} && ($preserve->{d} eq 'all')) {
push @out, "first daily in week (starting on $preserve->{dow}) for $preserve->{w} weeks" if($preserve->{w});
unless($preserve->{w} && ($preserve->{w} eq 'all')) {
push @out, "last weekly of month for $preserve->{m} months" if($preserve->{m});
push @out, "first weekly of month for $preserve->{m} months" if($preserve->{m});
unless($preserve->{m} && ($preserve->{m} eq 'all')) {
push @out, "last weekly of year for $preserve->{y} years" if($preserve->{y});
push @out, "first weekly of year for $preserve->{y} years" if($preserve->{y});
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions doc/btrbk.conf.5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH "btrbk.conf" "5" "2016-03-31" "btrbk v0.23.0-dev" ""
.TH "btrbk.conf" "5" "2016-04-12" "btrbk v0.23.0-dev" ""
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
Expand Down Expand Up @@ -247,7 +247,7 @@ With the following semantics:
.B hourly
.RS 4
Defines how many hours back hourly backups should be preserved. The
last backup of an hour is considered an hourly backup. Note that if
first backup of an hour is considered an hourly backup. Note that if
you use <hourly> scheduling, make sure to also set
\fItimestamp_format\fR to \[lq]long\[rq], or the scheduler will
interpret the time as "00:00" (midnight).
Expand All @@ -256,7 +256,7 @@ interpret the time as "00:00" (midnight).
.B daily
.RS 4
Defines how many days back daily backups should be preserved. The
last backup of a day is considered a daily backup.
first backup of a day is considered a daily backup.
.RE
.PP
.B weekly
Expand All @@ -270,14 +270,14 @@ as a weekly backup.
.B monthly
.RS 4
Defines how many months back monthly backups should be
preserved. Every last weekly backup in a month is considered a
preserved. Every first weekly backup in a month is considered a
monthly backup.
.RE
.PP
.B yearly
.RS 4
Defines for how many years back yearly backups should be
preserved. Every last monthly backup in a year is considered a yearly
preserved. Every first monthly backup in a year is considered a yearly
backup.
.RE
.PP
Expand Down

0 comments on commit bd34d9f

Please sign in to comment.