Skip to content
Permalink
Browse files

Merge pull request #362 from shodanshok/master

Changed (and simplified) DST handling
  • Loading branch information...
jimsalterjrs committed May 22, 2019
2 parents 34ef1bb + bfffd97 commit 0168ee3a3c74f865c88c8a13e58971a87bbb5589
Showing with 8 additions and 50 deletions.
  1. +1 −1 README.md
  2. +5 −47 sanoid
  3. +2 −2 tests/2_dst_handling/run.sh
@@ -9,7 +9,7 @@ More prosaically, you can use Sanoid to create, automatically thin, and monitor
* * * * * 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:
52 sanoid
@@ -357,19 +357,6 @@ sub take_snapshots {

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"; }
foreach my $section (keys %config) {
if ($section =~ /^template/) { next; }
@@ -393,9 +380,6 @@ sub take_snapshots {
my @preferredtime;
my $lastpreferred;

# to avoid duplicates with DST
my $dateSuffix = "";

if ($type eq 'frequently') {
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{'year'};
$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
} elsif ($type eq 'daily') {
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{'year'};
$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()) {
$lastpreferred -= 60*60*24;

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
$preferredtime[3] -= 1; # preferred time is later today - so look at yesterday's
$lastpreferred = timelocal(@preferredtime);
}
} elsif ($type eq 'weekly') {
# calculate offset in seconds for the desired weekday
my $offset = 0;
@@ -505,9 +463,9 @@ sub take_snapshots {

# use zfs (atomic) recursion if specified in config
if ($config{$section}{'zfs_recursion'}) {
push(@newsnaps, "$path\@autosnap_$datestamp{'sortable'}${dateSuffix}_$type\@");
push(@newsnaps, "$path\@autosnap_$datestamp{'sortable'}_$type\@");
} 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_TARGET="" # root
RESULT="/tmp/sanoid_test_result"
RESULT_CHECKSUM="a916d9cd46f4b80f285d069f3497d02671bbb1bfd12b43ef93531cbdaf89d55c"
RESULT_CHECKSUM="0a6336ccdc948c69563cb56994d190aebbc9b21588aef17bb97e51ae074f879a"

# UTC timestamp of start and end
START="1509141600"
@@ -49,6 +49,6 @@ done
saveSnapshotList "${POOL_NAME}" "${RESULT}"

# hourly daily monthly
verifySnapshotList "${RESULT}" 73 3 1 "${RESULT_CHECKSUM}"
verifySnapshotList "${RESULT}" 72 3 1 "${RESULT_CHECKSUM}"

# one more hour because of DST

0 comments on commit 0168ee3

Please sign in to comment.
You can’t perform that action at this time.