Merge pull request #244 from mouse-reeve/cron

Adds database backup crontab
This commit is contained in:
Mouse Reeve 2020-10-28 16:33:49 -07:00 committed by GitHub
commit 9c68b6d430
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 1 deletions

View file

@ -24,10 +24,11 @@ services:
- ./certbot/logs:/var/log/letsencrypt
- ./certbot/data:/var/www/certbot
db:
image: postgres
build: postgres-docker
env_file: .env
volumes:
- pgdata:/var/lib/postgresql/data
- backups:/backups
networks:
- main
web:
@ -71,6 +72,7 @@ services:
restart: on-failure
volumes:
pgdata:
backups:
static_volume:
media_volume:
networks:

View file

@ -0,0 +1,10 @@
FROM postgres:latest
# crontab
RUN mkdir /backups
COPY ./backup.sh /backups
COPY ./cronfile /etc/cron.d/cronfile
RUN apt-get update && apt-get -y install cron
RUN chmod 0644 /etc/cron.d/cronfile
RUN crontab /etc/cron.d/cronfile
RUN touch /var/log/cron.log

3
postgres-docker/backup.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
filename=backup__$(date +%F)
pg_dump -U fedireads > /backups/$filename.sql

2
postgres-docker/cronfile Normal file
View file

@ -0,0 +1,2 @@
0 0 * * * /backups/db_bashup.sh