From 00b920682913641732981c233acd9262671719af Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Thu, 9 Nov 2017 09:44:40 +0100 Subject: [PATCH 1/3] implemented weekly period --- sanoid | 26 +++++++++++++++++++++++--- sanoid.defaults.conf | 11 +++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/sanoid b/sanoid index d6e58ce..9b6c815 100755 --- a/sanoid +++ b/sanoid @@ -121,15 +121,16 @@ sub monitor_snapshots { my $path = $config{$section}{'path'}; push @paths, $path; - my @types = ('yearly','monthly','daily','hourly'); + my @types = ('yearly','monthly', 'weekly', 'daily','hourly'); foreach my $type (@types) { my $smallerperiod = 0; # we need to set the period length in seconds first if ($type eq 'hourly') { $smallerperiod = 60; } elsif ($type eq 'daily') { $smallerperiod = 60*60; } - elsif ($type eq 'monthly') { $smallerperiod = 60*60*24; } - elsif ($type eq 'yearly') { $smallerperiod = 60*60*24; } + elsif ($type eq 'weekly') { $smallerperiod = 60*60*24; } + elsif ($type eq 'monthly') { $smallerperiod = 60*60*24*7; } + elsif ($type eq 'yearly') { $smallerperiod = 60*60*24*31; } my $typewarn = $type . '_warn'; my $typecrit = $type . '_crit'; @@ -202,6 +203,7 @@ sub prune_snapshots { # we need to set the period length in seconds first if ($type eq 'hourly') { $period = 60*60; } elsif ($type eq 'daily') { $period = 60*60*24; } + elsif ($type eq 'weekly') { $period = 60*60*24*7; } elsif ($type eq 'monthly') { $period = 60*60*24*31; } elsif ($type eq 'yearly') { $period = 60*60*24*365.25; } @@ -309,6 +311,24 @@ sub take_snapshots { push @preferredtime,$datestamp{'year'}; $lastpreferred = timelocal(@preferredtime); if ($lastpreferred > time()) { $lastpreferred -= 60*60*24; } # preferred time is later today - so look at yesterday's + } elsif ($type eq 'weekly') { + # calculate offset in seconds for the desired weekday + my $offset; + if ($config{$section}{'weekly_wday'} < $datestamp{'wday'}) { + $offset += 6; + } + $offset += $config{$section}{'weekly_wday'} - $datestamp{'wday'}; + $offset *= 60*60*24; # full day + + push @preferredtime,0; # try to hit 0 seconds + push @preferredtime,$config{$section}{'weekly_min'}; + push @preferredtime,$config{$section}{'weekly_hour'}; + push @preferredtime,$datestamp{'mday'}; + push @preferredtime,($datestamp{'mon'}-1); # january is month 0 + push @preferredtime,$datestamp{'year'}; + $lastpreferred = timelocal(@preferredtime); + $lastpreferred -= $offset; + if ($lastpreferred > time()) { $lastpreferred -= 60*60*24*7; } # preferred time is later today - so look at yesterday's } elsif ($type eq 'monthly') { push @preferredtime,0; # try to hit 0 seconds push @preferredtime,$config{$section}{'monthly_min'}; diff --git a/sanoid.defaults.conf b/sanoid.defaults.conf index 35c804d..7187104 100644 --- a/sanoid.defaults.conf +++ b/sanoid.defaults.conf @@ -24,6 +24,7 @@ process_children_only = autoprune = yes hourly = 48 daily = 90 +weekly = 0 monthly = 6 yearly = 0 min_percent_free = 10 @@ -40,6 +41,10 @@ hourly_min = 0 # daily - at 23:59 (most people expect a daily to contain everything done DURING that day) daily_hour = 23 daily_min = 59 +# weekly -at 23:30 each Monday +weekly_wday = 1 +weekly_hour = 23 +weekly_min = 30 # monthly - immediately at the beginning of the month (ie 00:00 of day 1) monthly_mday = 1 monthly_hour = 0 @@ -66,7 +71,9 @@ hourly_warn = 90 hourly_crit = 360 daily_warn = 28 daily_crit = 32 -monthly_warn = 32 -monthly_crit = 35 +weekly_warn = 7 +weekly_crit = 10 +monthly_warn = 5 +monthly_crit = 6 yearly_warn = 0 yearly_crit = 0 From 4649704046cee190c8482e00e79b9b8d408829e4 Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Thu, 9 Nov 2017 17:41:52 +0100 Subject: [PATCH 2/3] codestyle fix and disable monitoring of weekly snapshots --- sanoid | 2 +- sanoid.defaults.conf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sanoid b/sanoid index 9b6c815..05c4def 100755 --- a/sanoid +++ b/sanoid @@ -121,7 +121,7 @@ sub monitor_snapshots { my $path = $config{$section}{'path'}; push @paths, $path; - my @types = ('yearly','monthly', 'weekly', 'daily','hourly'); + my @types = ('yearly','monthly','weekly','daily','hourly'); foreach my $type (@types) { my $smallerperiod = 0; diff --git a/sanoid.defaults.conf b/sanoid.defaults.conf index 7187104..ff79ebb 100644 --- a/sanoid.defaults.conf +++ b/sanoid.defaults.conf @@ -71,8 +71,8 @@ hourly_warn = 90 hourly_crit = 360 daily_warn = 28 daily_crit = 32 -weekly_warn = 7 -weekly_crit = 10 +weekly_warn = 0 +weekly_crit = 0 monthly_warn = 5 monthly_crit = 6 yearly_warn = 0 From 2a3d91e4465ea35ce68548915aeaf4eb1ec75745 Mon Sep 17 00:00:00 2001 From: Christoph Klaffl Date: Wed, 13 Dec 2017 00:44:48 +0100 Subject: [PATCH 3/3] fixed weekly snapshot interval --- sanoid | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sanoid b/sanoid index 05c4def..792497a 100755 --- a/sanoid +++ b/sanoid @@ -313,9 +313,9 @@ sub take_snapshots { if ($lastpreferred > time()) { $lastpreferred -= 60*60*24; } # preferred time is later today - so look at yesterday's } elsif ($type eq 'weekly') { # calculate offset in seconds for the desired weekday - my $offset; + my $offset = 0; if ($config{$section}{'weekly_wday'} < $datestamp{'wday'}) { - $offset += 6; + $offset += 7; } $offset += $config{$section}{'weekly_wday'} - $datestamp{'wday'}; $offset *= 60*60*24; # full day @@ -327,7 +327,7 @@ sub take_snapshots { push @preferredtime,($datestamp{'mon'}-1); # january is month 0 push @preferredtime,$datestamp{'year'}; $lastpreferred = timelocal(@preferredtime); - $lastpreferred -= $offset; + $lastpreferred += $offset; if ($lastpreferred > time()) { $lastpreferred -= 60*60*24*7; } # preferred time is later today - so look at yesterday's } elsif ($type eq 'monthly') { push @preferredtime,0; # try to hit 0 seconds