Skip to content

Commit

Permalink
skip backup when next run is in the past
Browse files Browse the repository at this point in the history
  • Loading branch information
nxcc committed Feb 2, 2024
1 parent 036e46c commit 3a08b3a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ the [docs directory](docs).
* `v1.6.4` routine update of deps
* `v1.6.5` routine update of Dockerfile
* `v1.7.0` correct cron execution even when host was suspended between runs
* `v1.7.1` skip backup when next run is in the past

[restic]: https://github.com/restic/restic
[sidecar]: test/deploy/demo/base/_common/deployment.yaml#L26-L48
Expand Down
10 changes: 9 additions & 1 deletion cmd/mcs-backup/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,11 @@ func initializeService(dryrun bool) {

select {

case <-sleepUntil(nextOccurrency.Start):
case t := <-sleepUntil(nextOccurrency.Start):
if t.IsZero() {
loki.Infof("skip backup")
continue
}
loki.Infof("backup triggered via cron")
if err := fullBackupRun(); err != nil {
loki.Errorf("cron: %v", err)
Expand Down Expand Up @@ -283,6 +287,10 @@ func sleepUntil(t time.Time) <-chan time.Time {
step := time.Duration(time.Minute)
go func(t time.Time) {
for {
if t.Before(time.Now()) {
tCh <- time.Time{}
return
}
delta := time.Until(t)
if delta > step {
time.Sleep(step)
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# https://hub.docker.com/_/golang
FROM golang:1.21.5 AS builder
FROM golang:1.21.6 AS builder
WORKDIR /go/src/app
ARG VERSION
COPY . ./
Expand All @@ -9,7 +9,7 @@ RUN CGO_ENABLED=0 go build -trimpath -tags timetzdata -ldflags="-s -w -X 'ma
FROM library/alpine:20231219

# https://github.com/restic/restic/releases
ARG RESTIC_VERSION=0.16.2
ARG RESTIC_VERSION=0.16.3
# https://github.com/mikefarah/yq/releases/
ARG YQ_VERSION=4.40.5
RUN set -x \
Expand Down

0 comments on commit 3a08b3a

Please sign in to comment.