From dfbc32617b199269b4f827da357ef01b57e676dc Mon Sep 17 00:00:00 2001 From: Ajay Date: Tue, 17 May 2022 01:29:49 -0400 Subject: [PATCH] Create an image for db backups --- .github/workflows/sb-server.yml | 10 +++++++++- containers/backup-db/Dockerfile | 13 +++++++++++++ containers/backup-db/backup.sh | 6 ++++++ containers/backup-db/forget.sh | 1 + {rsync => containers/rsync}/Dockerfile | 0 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 containers/backup-db/Dockerfile create mode 100644 containers/backup-db/backup.sh create mode 100644 containers/backup-db/forget.sh rename {rsync => containers/rsync}/Dockerfile (100%) diff --git a/.github/workflows/sb-server.yml b/.github/workflows/sb-server.yml index 1e46555..89c60f8 100644 --- a/.github/workflows/sb-server.yml +++ b/.github/workflows/sb-server.yml @@ -20,6 +20,14 @@ jobs: with: name: "rsync-host" username: "ajayyy" - folder: "./rsync" + folder: "./containers/rsync" + secrets: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + backup-db: + uses: ./.github/workflows/docker-build.yml + with: + name: "db-backup" + username: "ajayyy" + folder: "./containers/backup-db" secrets: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/containers/backup-db/Dockerfile b/containers/backup-db/Dockerfile new file mode 100644 index 0000000..be2d7a3 --- /dev/null +++ b/containers/backup-db/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine +RUN apk add postgresql-client +RUN apk add restic --repository http://dl-cdn.alpinelinux.org/alpine/latest-stable/community/ + +COPY ./backup.sh /usr/src/app/backup.sh +RUN chmod +x /usr/src/app/backup.sh +COPY ./backup.sh /usr/src/app/forget.sh +RUN chmod +x /usr/src/app/forget.sh + +RUN echo '30 * * * * /usr/src/app/backup.sh' >> /etc/crontabs/root +RUN echo '10 0 * * 1 /usr/src/app/forget.sh' >> /etc/crontabs/root + +CMD crond -l 2 -f \ No newline at end of file diff --git a/containers/backup-db/backup.sh b/containers/backup-db/backup.sh new file mode 100644 index 0000000..cc847e5 --- /dev/null +++ b/containers/backup-db/backup.sh @@ -0,0 +1,6 @@ +mkdir ./dump + +pg_dump -f ./dump/sponsorTimes.dump sponsorTimes +pg_dump -f ./dump/privateDB.dump privateDB + +restic backup ./dump \ No newline at end of file diff --git a/containers/backup-db/forget.sh b/containers/backup-db/forget.sh new file mode 100644 index 0000000..eaa6165 --- /dev/null +++ b/containers/backup-db/forget.sh @@ -0,0 +1 @@ +restic forget --prune --keep-last 48 --keep-daily 7 --keep-weekly 8 \ No newline at end of file diff --git a/rsync/Dockerfile b/containers/rsync/Dockerfile similarity index 100% rename from rsync/Dockerfile rename to containers/rsync/Dockerfile