diff --git a/Dockerfile b/Dockerfile index 93113262..f03d84dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,12 +8,3 @@ COPY requirements.txt /app/ RUN pip install -r requirements.txt COPY ./bookwyrm /app COPY ./celerywyrm /app - -# crontab -COPY ./db_backup.sh /app -RUN apt-get update && apt-get -y install cron -COPY db-backups-cron /etc/cron.d/db-backups-cron -RUN chmod 0644 /etc/cron.d/db-backups-cron -RUN crontab /etc/cron.d/db-backups-cron -RUN touch /var/log/cron.log -CMD cron && tail -f /var/log/cron.log diff --git a/db-backups-cron b/db-backups-cron deleted file mode 100644 index d42df0e2..00000000 --- a/db-backups-cron +++ /dev/null @@ -1 +0,0 @@ -0 0 * * * /app/db_bashup.sh diff --git a/db_backup.sh b/db_backup.sh deleted file mode 100755 index bff79f9a..00000000 --- a/db_backup.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -filename=backup__$(date +%F) -pg_dump -U fedireads | gzip > $filename.gz diff --git a/docker-compose.yml b/docker-compose.yml index 29ec83ee..169a7174 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,10 +14,11 @@ services: - static_volume:/app/static - media_volume:/app/images db: - image: postgres + build: postgres-docker env_file: .env volumes: - pgdata:/var/lib/postgresql/data + - backups:/backups networks: - main web: @@ -58,6 +59,7 @@ services: restart: on-failure volumes: pgdata: + backups: static_volume: media_volume: networks: diff --git a/postgres-docker/Dockerfile b/postgres-docker/Dockerfile new file mode 100644 index 00000000..7217826b --- /dev/null +++ b/postgres-docker/Dockerfile @@ -0,0 +1,10 @@ +FROM postgres:latest + +# crontab +RUN mkdir /backups +COPY ./db_backup.sh /backups +COPY ./db-backups-cron /etc/cron.d/db-backups-cron +RUN apt-get update && apt-get -y install cron +RUN chmod 0644 /etc/cron.d/db-backups-cron +RUN crontab /etc/cron.d/db-backups-cron +RUN touch /var/log/cron.log diff --git a/postgres-docker/db-backups-cron b/postgres-docker/db-backups-cron new file mode 100644 index 00000000..952c66ea --- /dev/null +++ b/postgres-docker/db-backups-cron @@ -0,0 +1,2 @@ +0 0 * * * /backups/db_bashup.sh + diff --git a/postgres-docker/db_backup.sh b/postgres-docker/db_backup.sh new file mode 100755 index 00000000..ef0e706d --- /dev/null +++ b/postgres-docker/db_backup.sh @@ -0,0 +1,3 @@ +#!/bin/bash +filename=backup__$(date +%F) +pg_dump -U fedireads > $filename.sql