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 * * *"