From d173dd6e4af4ebc7898bd6406e2f3f261e68eb17 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 10 Sep 2019 21:15:08 -0300 Subject: [PATCH] borg --- Dockerfile | 12 ++++++++++++ backup.sh | 16 ++++++++++++++++ monit.conf | 4 ++++ 3 files changed, 32 insertions(+) create mode 100644 backup.sh create mode 100644 monit.conf diff --git a/Dockerfile b/Dockerfile index 59c5898..bc376ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,14 @@ FROM sutty/monit:latest MAINTAINER "f " + +ENV BORG_HOST_ID borg +ENV BORG_PASSPHRASE "" +ENV KEEP 30 + +COPY ./monit.conf /etc/monit.d/borg.conf +COPY ./backup.sh /usr/local/bin/backup + +RUN apk add --no-cache borgbackup + +VOLUME /srv/data +VOLUME /srv/backups diff --git a/backup.sh b/backup.sh new file mode 100644 index 0000000..b546780 --- /dev/null +++ b/backup.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +# Password can't be empty +test -n "${BORG_PASSPHRASE}" + +date="$(date +%F)" +orig=/srv/data +dest=/srv/backups + +test -f "${dest}/config" || borg init --encryption=repokey "${dest}" + +borg create -v --stats "${dest}::${date}" "${orig}" +borg prune -v --stats --keep-daily ${KEEP} "${dest}" + +exit $? diff --git a/monit.conf b/monit.conf new file mode 100644 index 0000000..c96f0fc --- /dev/null +++ b/monit.conf @@ -0,0 +1,4 @@ +check program backup + with path "/usr/local/bin/backup" + if status != 0 then alert + every "53 3 * * *"