From 6dc493b37e059264b69e147edca4598cf0db1f9f Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 17 Aug 2023 17:00:22 +0200 Subject: [PATCH] feat: use cron to run backups --- Dockerfile | 7 +++++++ entrypoint.sh | 15 ++++++++------- run-backup.sh | 10 ++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100755 run-backup.sh diff --git a/Dockerfile b/Dockerfile index e36e0b5..ec8c180 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,12 @@ FROM kopia/kopia +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install -y cron && rm -rf /var/lib/apt/lists/* + +ARG KOPIA_CRON_TIMES="*/30 * * * *" +ENV KOPIA_CRON_TIMES ${KOPIA_CRON_TIMES} + +ADD run-backup.sh / ADD entrypoint.sh / ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/entrypoint.sh b/entrypoint.sh index 4e98ae0..5011134 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,10 +1,11 @@ -#!/bin/sh +#!/bin/sh -kopia --version +CRONTAB=/etc/cron.d/kopia-backup -kopia repository connect filesystem \ - --path /repository \ - --override-hostname ${KOPIA_HOSTNAME} \ - --override-username ${KOPIA_USERNAME} +echo "Running cron with schedule ${KOPIA_CRON_TIMES}" -sleep infinity +echo "${KOPIA_CRON_TIMES} /run-backup.sh > /dev/stdout" > ${CRONTAB} +chmod 0644 ${CRONTAB} +crontab ${CRONTAB} + +cron -f diff --git a/run-backup.sh b/run-backup.sh new file mode 100755 index 0000000..894501d --- /dev/null +++ b/run-backup.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +kopia --version + +kopia repository connect filesystem \ + --path /repository \ + --override-hostname ${KOPIA_HOSTNAME} \ + --override-username ${KOPIA_USERNAME} + +kopia snapshot create /backup