Merge pull request #157 from phreaker0/frequently
implemented frequent snapshots with configurable period
This commit is contained in:
commit
8d24fab041
|
@ -28,6 +28,7 @@ And its /etc/sanoid/sanoid.conf might look something like this:
|
||||||
#############################
|
#############################
|
||||||
|
|
||||||
[template_production]
|
[template_production]
|
||||||
|
frequently = 0
|
||||||
hourly = 36
|
hourly = 36
|
||||||
daily = 30
|
daily = 30
|
||||||
monthly = 3
|
monthly = 3
|
||||||
|
|
33
sanoid
33
sanoid
|
@ -5,6 +5,7 @@
|
||||||
# project's Git repository at https://github.com/jimsalterjrs/sanoid/blob/master/LICENSE.
|
# project's Git repository at https://github.com/jimsalterjrs/sanoid/blob/master/LICENSE.
|
||||||
|
|
||||||
$::VERSION = '1.4.18';
|
$::VERSION = '1.4.18';
|
||||||
|
my $MINIMUM_DEFAULTS_VERSION = 2;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
@ -125,12 +126,13 @@ sub monitor_snapshots {
|
||||||
my $path = $config{$section}{'path'};
|
my $path = $config{$section}{'path'};
|
||||||
push @paths, $path;
|
push @paths, $path;
|
||||||
|
|
||||||
my @types = ('yearly','monthly','daily','hourly');
|
my @types = ('yearly','monthly','daily','hourly','frequently');
|
||||||
foreach my $type (@types) {
|
foreach my $type (@types) {
|
||||||
|
|
||||||
my $smallerperiod = 0;
|
my $smallerperiod = 0;
|
||||||
# we need to set the period length in seconds first
|
# we need to set the period length in seconds first
|
||||||
if ($type eq 'hourly') { $smallerperiod = 60; }
|
if ($type eq 'frequently') { $smallerperiod = 1; }
|
||||||
|
elsif ($type eq 'hourly') { $smallerperiod = 60; }
|
||||||
elsif ($type eq 'daily') { $smallerperiod = 60*60; }
|
elsif ($type eq 'daily') { $smallerperiod = 60*60; }
|
||||||
elsif ($type eq 'monthly') { $smallerperiod = 60*60*24; }
|
elsif ($type eq 'monthly') { $smallerperiod = 60*60*24; }
|
||||||
elsif ($type eq 'yearly') { $smallerperiod = 60*60*24; }
|
elsif ($type eq 'yearly') { $smallerperiod = 60*60*24; }
|
||||||
|
@ -259,7 +261,8 @@ sub prune_snapshots {
|
||||||
unless ($type =~ /ly$/) { next; }
|
unless ($type =~ /ly$/) { next; }
|
||||||
|
|
||||||
# we need to set the period length in seconds first
|
# we need to set the period length in seconds first
|
||||||
if ($type eq 'hourly') { $period = 60*60; }
|
if ($type eq 'frequently') { $period = 60 * $config{$section}{'frequent_period'}; }
|
||||||
|
elsif ($type eq 'hourly') { $period = 60*60; }
|
||||||
elsif ($type eq 'daily') { $period = 60*60*24; }
|
elsif ($type eq 'daily') { $period = 60*60*24; }
|
||||||
elsif ($type eq 'monthly') { $period = 60*60*24*31; }
|
elsif ($type eq 'monthly') { $period = 60*60*24*31; }
|
||||||
elsif ($type eq 'yearly') { $period = 60*60*24*365.25; }
|
elsif ($type eq 'yearly') { $period = 60*60*24*365.25; }
|
||||||
|
@ -373,7 +376,18 @@ sub take_snapshots {
|
||||||
# to avoid duplicates with DST
|
# to avoid duplicates with DST
|
||||||
my $dateSuffix = "";
|
my $dateSuffix = "";
|
||||||
|
|
||||||
if ($type eq 'hourly') {
|
if ($type eq 'frequently') {
|
||||||
|
my $frequentslice = int($datestamp{'min'} / $config{$section}{'frequent_period'});
|
||||||
|
|
||||||
|
push @preferredtime,0; # try to hit 0 seconds
|
||||||
|
push @preferredtime,$frequentslice * $config{$section}{'frequent_period'};
|
||||||
|
push @preferredtime,$datestamp{'hour'};
|
||||||
|
push @preferredtime,$datestamp{'mday'};
|
||||||
|
push @preferredtime,($datestamp{'mon'}-1); # january is month 0
|
||||||
|
push @preferredtime,$datestamp{'year'};
|
||||||
|
$lastpreferred = timelocal(@preferredtime);
|
||||||
|
if ($lastpreferred > time()) { $lastpreferred -= 60 * $config{$section}{'frequent_period'}; } # preferred time is later this frequent period - so look at last frequent period
|
||||||
|
} elsif ($type eq 'hourly') {
|
||||||
push @preferredtime,0; # try to hit 0 seconds
|
push @preferredtime,0; # try to hit 0 seconds
|
||||||
push @preferredtime,$config{$section}{'hourly_min'};
|
push @preferredtime,$config{$section}{'hourly_min'};
|
||||||
push @preferredtime,$datestamp{'hour'};
|
push @preferredtime,$datestamp{'hour'};
|
||||||
|
@ -665,6 +679,17 @@ sub init {
|
||||||
my @istrue=(1,"true","True","TRUE","yes","Yes","YES","on","On","ON");
|
my @istrue=(1,"true","True","TRUE","yes","Yes","YES","on","On","ON");
|
||||||
my @isfalse=(0,"false","False","FALSE","no","No","NO","off","Off","OFF");
|
my @isfalse=(0,"false","False","FALSE","no","No","NO","off","Off","OFF");
|
||||||
|
|
||||||
|
# check if default configuration file is up to date
|
||||||
|
my $defaults_version = 1;
|
||||||
|
if (defined $defaults{'version'}{'version'}) {
|
||||||
|
$defaults_version = $defaults{'version'}{'version'};
|
||||||
|
delete $defaults{'version'};
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($defaults_version < $MINIMUM_DEFAULTS_VERSION) {
|
||||||
|
die "FATAL: you're using sanoid.defaults.conf v$defaults_version, this version of sanoid requires a minimum sanoid.defaults.conf v$MINIMUM_DEFAULTS_VERSION";
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $section (keys %ini) {
|
foreach my $section (keys %ini) {
|
||||||
|
|
||||||
# first up - die with honor if unknown parameters are set in any modules or templates by the user.
|
# first up - die with honor if unknown parameters are set in any modules or templates by the user.
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
daily = 60
|
daily = 60
|
||||||
|
|
||||||
[template_production]
|
[template_production]
|
||||||
|
frequently = 0
|
||||||
hourly = 36
|
hourly = 36
|
||||||
daily = 30
|
daily = 30
|
||||||
monthly = 3
|
monthly = 3
|
||||||
|
@ -49,6 +50,7 @@
|
||||||
|
|
||||||
[template_backup]
|
[template_backup]
|
||||||
autoprune = yes
|
autoprune = yes
|
||||||
|
frequently = 0
|
||||||
hourly = 30
|
hourly = 30
|
||||||
daily = 90
|
daily = 90
|
||||||
monthly = 12
|
monthly = 12
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
# #
|
# #
|
||||||
# you have been warned. #
|
# you have been warned. #
|
||||||
###################################################################################
|
###################################################################################
|
||||||
|
[version]
|
||||||
|
version = 2
|
||||||
|
|
||||||
[template_default]
|
[template_default]
|
||||||
|
|
||||||
|
@ -17,12 +19,25 @@ use_template =
|
||||||
process_children_only =
|
process_children_only =
|
||||||
skip_children =
|
skip_children =
|
||||||
|
|
||||||
|
# for snapshots shorter than one hour, the period duration must be defined
|
||||||
|
# in minutes. Because they are executed within a full hour, the selected
|
||||||
|
# value should divide 60 minutes without remainder so taken snapshots
|
||||||
|
# are apart in equal intervals. Values larger than 59 aren't practical
|
||||||
|
# as only one snapshot will be taken on each full hour in this case.
|
||||||
|
# examples:
|
||||||
|
# frequent_period = 15 -> four snapshot each hour 15 minutes apart
|
||||||
|
# frequent_period = 5 -> twelve snapshots each hour 5 minutes apart
|
||||||
|
# frequent_period = 45 -> two snapshots each hour with different time gaps
|
||||||
|
# between them: 45 minutes and 15 minutes in this case
|
||||||
|
frequent_period = 15
|
||||||
|
|
||||||
# If any snapshot type is set to 0, we will not take snapshots for it - and will immediately
|
# If any snapshot type is set to 0, we will not take snapshots for it - and will immediately
|
||||||
# prune any of those type snapshots already present.
|
# prune any of those type snapshots already present.
|
||||||
#
|
#
|
||||||
# Otherwise, if autoprune is set, we will prune any snapshots of that type which are older
|
# Otherwise, if autoprune is set, we will prune any snapshots of that type which are older
|
||||||
# than (setting * periodicity) - so if daily = 90, we'll prune any dailies older than 90 days.
|
# than (setting * periodicity) - so if daily = 90, we'll prune any dailies older than 90 days.
|
||||||
autoprune = yes
|
autoprune = yes
|
||||||
|
frequently = 0
|
||||||
hourly = 48
|
hourly = 48
|
||||||
daily = 90
|
daily = 90
|
||||||
monthly = 6
|
monthly = 6
|
||||||
|
@ -63,6 +78,8 @@ yearly_min = 0
|
||||||
monitor = yes
|
monitor = yes
|
||||||
monitor_dont_warn = no
|
monitor_dont_warn = no
|
||||||
monitor_dont_crit = no
|
monitor_dont_crit = no
|
||||||
|
frequently_warn = 0
|
||||||
|
frequently_crit = 0
|
||||||
hourly_warn = 90
|
hourly_warn = 90
|
||||||
hourly_crit = 360
|
hourly_crit = 360
|
||||||
daily_warn = 28
|
daily_warn = 28
|
||||||
|
|
Loading…
Reference in New Issue