Merge pull request #362 from shodanshok/master
Changed (and simplified) DST handling
This commit is contained in:
commit
0168ee3a3c
|
@ -9,7 +9,7 @@ More prosaically, you can use Sanoid to create, automatically thin, and monitor
|
||||||
* * * * * TZ=UTC /usr/local/bin/sanoid --cron
|
* * * * * TZ=UTC /usr/local/bin/sanoid --cron
|
||||||
```
|
```
|
||||||
|
|
||||||
`Note`: Using UTC as timezone is recommend to prevent problems with daylight saving times
|
**`IMPORTANT NOTE`**: using a local timezone will result in a single hourly snapshot to be **skipped** during `daylight->nodaylight` transition. To avoid that, using UTC as timezone is recommend whenever possible.
|
||||||
|
|
||||||
And its /etc/sanoid/sanoid.conf might look something like this:
|
And its /etc/sanoid/sanoid.conf might look something like this:
|
||||||
|
|
||||||
|
|
50
sanoid
50
sanoid
|
@ -357,19 +357,6 @@ sub take_snapshots {
|
||||||
|
|
||||||
my @newsnaps;
|
my @newsnaps;
|
||||||
|
|
||||||
# get utc timestamp of the current day for DST check
|
|
||||||
my $daystartUtc = timelocal(0, 0, 0, $datestamp{'mday'}, ($datestamp{'mon'}-1), $datestamp{'year'});
|
|
||||||
my ($isdst) = (localtime($daystartUtc))[8];
|
|
||||||
my $dstOffset = 0;
|
|
||||||
|
|
||||||
if ($isdst ne $datestamp{'isdst'}) {
|
|
||||||
# current dst is different then at the beginning og the day
|
|
||||||
if ($isdst) {
|
|
||||||
# DST ended in the current day
|
|
||||||
$dstOffset = 60*60;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($args{'verbose'}) { print "INFO: taking snapshots...\n"; }
|
if ($args{'verbose'}) { print "INFO: taking snapshots...\n"; }
|
||||||
foreach my $section (keys %config) {
|
foreach my $section (keys %config) {
|
||||||
if ($section =~ /^template/) { next; }
|
if ($section =~ /^template/) { next; }
|
||||||
|
@ -393,9 +380,6 @@ sub take_snapshots {
|
||||||
my @preferredtime;
|
my @preferredtime;
|
||||||
my $lastpreferred;
|
my $lastpreferred;
|
||||||
|
|
||||||
# to avoid duplicates with DST
|
|
||||||
my $dateSuffix = "";
|
|
||||||
|
|
||||||
if ($type eq 'frequently') {
|
if ($type eq 'frequently') {
|
||||||
my $frequentslice = int($datestamp{'min'} / $config{$section}{'frequent_period'});
|
my $frequentslice = int($datestamp{'min'} / $config{$section}{'frequent_period'});
|
||||||
|
|
||||||
|
@ -415,13 +399,6 @@ sub take_snapshots {
|
||||||
push @preferredtime,($datestamp{'mon'}-1); # january is month 0
|
push @preferredtime,($datestamp{'mon'}-1); # january is month 0
|
||||||
push @preferredtime,$datestamp{'year'};
|
push @preferredtime,$datestamp{'year'};
|
||||||
$lastpreferred = timelocal(@preferredtime);
|
$lastpreferred = timelocal(@preferredtime);
|
||||||
|
|
||||||
if ($dstOffset ne 0) {
|
|
||||||
# timelocal doesn't take DST into account
|
|
||||||
$lastpreferred += $dstOffset;
|
|
||||||
# DST ended, avoid duplicates
|
|
||||||
$dateSuffix = "_y";
|
|
||||||
}
|
|
||||||
if ($lastpreferred > time()) { $lastpreferred -= 60*60; } # preferred time is later this hour - so look at last hour's
|
if ($lastpreferred > time()) { $lastpreferred -= 60*60; } # preferred time is later this hour - so look at last hour's
|
||||||
} elsif ($type eq 'daily') {
|
} elsif ($type eq 'daily') {
|
||||||
push @preferredtime,0; # try to hit 0 seconds
|
push @preferredtime,0; # try to hit 0 seconds
|
||||||
|
@ -431,29 +408,10 @@ sub take_snapshots {
|
||||||
push @preferredtime,($datestamp{'mon'}-1); # january is month 0
|
push @preferredtime,($datestamp{'mon'}-1); # january is month 0
|
||||||
push @preferredtime,$datestamp{'year'};
|
push @preferredtime,$datestamp{'year'};
|
||||||
$lastpreferred = timelocal(@preferredtime);
|
$lastpreferred = timelocal(@preferredtime);
|
||||||
|
|
||||||
# timelocal doesn't take DST into account
|
|
||||||
$lastpreferred += $dstOffset;
|
|
||||||
|
|
||||||
# check if the planned time has different DST flag than the current
|
|
||||||
my ($isdst) = (localtime($lastpreferred))[8];
|
|
||||||
if ($isdst ne $datestamp{'isdst'}) {
|
|
||||||
if (!$isdst) {
|
|
||||||
# correct DST difference
|
|
||||||
$lastpreferred -= 60*60;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($lastpreferred > time()) {
|
if ($lastpreferred > time()) {
|
||||||
$lastpreferred -= 60*60*24;
|
$preferredtime[3] -= 1; # preferred time is later today - so look at yesterday's
|
||||||
|
$lastpreferred = timelocal(@preferredtime);
|
||||||
if ($dstOffset ne 0) {
|
|
||||||
# because we are going back one day
|
|
||||||
# the DST difference has to be accounted
|
|
||||||
# for in reverse now
|
|
||||||
$lastpreferred -= 2*$dstOffset;
|
|
||||||
}
|
}
|
||||||
} # preferred time is later today - so look at yesterday's
|
|
||||||
} elsif ($type eq 'weekly') {
|
} elsif ($type eq 'weekly') {
|
||||||
# calculate offset in seconds for the desired weekday
|
# calculate offset in seconds for the desired weekday
|
||||||
my $offset = 0;
|
my $offset = 0;
|
||||||
|
@ -505,9 +463,9 @@ sub take_snapshots {
|
||||||
|
|
||||||
# use zfs (atomic) recursion if specified in config
|
# use zfs (atomic) recursion if specified in config
|
||||||
if ($config{$section}{'zfs_recursion'}) {
|
if ($config{$section}{'zfs_recursion'}) {
|
||||||
push(@newsnaps, "$path\@autosnap_$datestamp{'sortable'}${dateSuffix}_$type\@");
|
push(@newsnaps, "$path\@autosnap_$datestamp{'sortable'}_$type\@");
|
||||||
} else {
|
} else {
|
||||||
push(@newsnaps, "$path\@autosnap_$datestamp{'sortable'}${dateSuffix}_$type");
|
push(@newsnaps, "$path\@autosnap_$datestamp{'sortable'}_$type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ set -x
|
||||||
POOL_NAME="sanoid-test-2"
|
POOL_NAME="sanoid-test-2"
|
||||||
POOL_TARGET="" # root
|
POOL_TARGET="" # root
|
||||||
RESULT="/tmp/sanoid_test_result"
|
RESULT="/tmp/sanoid_test_result"
|
||||||
RESULT_CHECKSUM="a916d9cd46f4b80f285d069f3497d02671bbb1bfd12b43ef93531cbdaf89d55c"
|
RESULT_CHECKSUM="0a6336ccdc948c69563cb56994d190aebbc9b21588aef17bb97e51ae074f879a"
|
||||||
|
|
||||||
# UTC timestamp of start and end
|
# UTC timestamp of start and end
|
||||||
START="1509141600"
|
START="1509141600"
|
||||||
|
@ -49,6 +49,6 @@ done
|
||||||
saveSnapshotList "${POOL_NAME}" "${RESULT}"
|
saveSnapshotList "${POOL_NAME}" "${RESULT}"
|
||||||
|
|
||||||
# hourly daily monthly
|
# hourly daily monthly
|
||||||
verifySnapshotList "${RESULT}" 73 3 1 "${RESULT_CHECKSUM}"
|
verifySnapshotList "${RESULT}" 72 3 1 "${RESULT_CHECKSUM}"
|
||||||
|
|
||||||
# one more hour because of DST
|
# one more hour because of DST
|
||||||
|
|
Loading…
Reference in New Issue