From b2336cee44cfb986cf08bceaa8dc42b37075e91f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 30 Sep 2020 12:36:20 +0300 Subject: [PATCH] add side container which backups tt-rss database once a week bump alpine image to 3.12 --- README.md | 1 + docker-compose.yml | 18 ++++++++++++++++++ src/app/Dockerfile | 6 ++++-- src/app/backup-database.sh | 22 ++++++++++++++++++++++ src/app/dcron.sh | 5 +++++ src/docker-compose.yml | 21 +++++++++++++++++++++ 6 files changed, 71 insertions(+), 2 deletions(-) create mode 100755 src/app/backup-database.sh create mode 100755 src/app/dcron.sh diff --git a/README.md b/README.md index 8034817..13260ad 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ General outline of the configuration is as follows: - Caddy has its http port exposed to the outside - optional SSL support via Caddy w/ automatic letsencrypt certificates - feed updates are handled via update daemon started in a separate container (updater) + - optional backups container which performs tt-rss database backup once a week ### Installation diff --git a/docker-compose.yml b/docker-compose.yml index fbd0c8a..ea2c947 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -48,6 +48,23 @@ services: - app command: /updater.sh + backups: + image: cthulhoo/ttrss-fpm-pgsql-static + restart: unless-stopped + environment: + - DB_TYPE=pgsql + - DB_HOST=db + - DB_NAME=${POSTGRES_USER} + - DB_USER=${POSTGRES_USER} + - DB_PASS=${POSTGRES_PASSWORD} + - OWNER_UID=${OWNER_UID} + - OWNER_GID=${OWNER_GID} + volumes: + - backups:/backups + depends_on: + - db + command: /dcron.sh -f + web: image: cthulhoo/ttrss-web restart: unless-stopped @@ -87,3 +104,4 @@ volumes: db: app: certs: + backups: diff --git a/src/app/Dockerfile b/src/app/Dockerfile index 9fcff5b..589ad8e 100644 --- a/src/app/Dockerfile +++ b/src/app/Dockerfile @@ -1,7 +1,7 @@ -FROM alpine:3.9 +FROM alpine:3.12 EXPOSE 9000/tcp -RUN apk add --no-cache php7 php7-fpm \ +RUN apk add --no-cache dcron php7 php7-fpm \ php7-pdo php7-gd php7-pgsql php7-pdo_pgsql php7-mbstring \ php7-intl php7-xml php7-curl php7-session \ php7-dom php7-fileinfo php7-json \ @@ -12,6 +12,8 @@ ADD startup.sh / ADD updater.sh / ADD index.php / ADD build-prepare.sh / +ADD dcron.sh / +ADD backup-database.sh /etc/periodic/weekly/backup-database RUN sed -i.bak 's/^listen = 127.0.0.1:9000/listen = 9000/' /etc/php7/php-fpm.d/www.conf RUN sed -i.bak 's/\(memory_limit =\) 128M/\1 256M/' /etc/php7/php.ini diff --git a/src/app/backup-database.sh b/src/app/backup-database.sh new file mode 100755 index 0000000..6918e24 --- /dev/null +++ b/src/app/backup-database.sh @@ -0,0 +1,22 @@ +#!/bin/sh -e + +DST_DIR=/backups +KEEP_DAYS=28 + +if pg_isready -h $DB_HOST -U $DB_USER; then + DST_FILE=ttrss-backup-$(date +%Y%m%d).sql.gz + + echo backing up tt-rss database to $DST_DIR/$DST_FILE... + + export PGPASSWORD=$DB_PASS + + pg_dump --clean -h $DB_HOST -U $DB_USER $DB_NAME | gzip > $DST_DIR/$DST_FILE + + echo cleaning up... + + find $DST_DIR -type f -name '*.sql.gz' -mtime +$KEEP_DAYS -delete + + echo done. +else + echo backup failed: database is not ready. +fi diff --git a/src/app/dcron.sh b/src/app/dcron.sh new file mode 100755 index 0000000..b16f15a --- /dev/null +++ b/src/app/dcron.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# https://github.com/dubiousjim/dcron/issues/13 +set -e + +/usr/sbin/crond "$@" diff --git a/src/docker-compose.yml b/src/docker-compose.yml index f5e52b9..c9be288 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -54,6 +54,26 @@ services: - app command: /updater.sh + backups: + image: cthulhoo/ttrss-fpm-pgsql-static:${BUILD_TAG} + build: + context: + ./app + restart: unless-stopped + environment: + - DB_TYPE=pgsql + - DB_HOST=db + - DB_NAME=${POSTGRES_USER} + - DB_USER=${POSTGRES_USER} + - DB_PASS=${POSTGRES_PASSWORD} + - OWNER_UID=${OWNER_UID} + - OWNER_GID=${OWNER_GID} + volumes: + - backups:/backups + depends_on: + - db + command: /dcron.sh -f + web: image: cthulhoo/ttrss-web:latest build: ./web @@ -96,3 +116,4 @@ volumes: db: app: certs: + backups: