diff --git a/Dockerfile b/Dockerfile index df9476b..98affab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,16 @@ -FROM kartoza/postgis:11.0-2.5 +FROM kartoza/postgis:12.1 MAINTAINER tim@kartoza.com -RUN apt-get -y update; apt-get install -y postgresql-client +RUN apt-get -y update; apt-get -y --no-install-recommends install postgresql-client cron RUN touch /var/log/cron.log COPY backups-cron /backups-cron COPY backups.sh /backups.sh COPY restore.sh /restore.sh COPY start.sh /start.sh +RUN chmod 0755 /*.sh ENTRYPOINT ["/bin/bash", "/start.sh"] +CMD ["/docker-entrypoint.sh"] + + diff --git a/backups-cron b/backups-cron index e7e3059..8721f2d 100755 --- a/backups-cron +++ b/backups-cron @@ -1,5 +1,5 @@ # For testing - run every minute -*/1 * * * * /backups.sh 2>&1 +#*/1 * * * * /backups.sh 2>&1 # Run the backups at 11pm each night 0 23 * * * /backups.sh 2>&1 diff --git a/build.sh b/build.sh index c7888f8..48dfc14 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ #!/bin/bash -docker build -t kartoza/pg-backup:11.0 . +docker build -t kartoza/pg-backup:12.0 . diff --git a/docker-compose.yml b/docker-compose.yml index 98e70b4..8abf7ea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,32 +1,38 @@ -# This is for testing on travis only -# For production we recommend to rather use -# image: kartoza/pg-backup -# in the dbbackup service -db: - image: kartoza/postgis - environment: - - ALLOW_IP_RANGE=0.0.0.0/0 - - POSTGRES_USER=docker - - POSTGRES_PASS=docker -dbbackup: - build: . - volumes: - - ./backups:/backups - environment: - - DUMPPREFIX=watchkeeper - # List databases to back up; defaults to all - - "DBLIST=gis" - # Remove backups older than (in days) - - REMOVE_BEFORE=30 - - POSTGRES_HOST=db - - POSTGRES_DBNAME=gis - - POSTGRES_USER=docker - - POSTGRES_PASS=docker - - POSTGRES_PORT=5432 - # For restore script - - TARGET_DB=gis - - WITH_POSTGIS=1 - - TARGET_ARCHIVE=/backups/target_archive.dmp - links: - - db:db +version: '2.1' + +volumes: + db-backups: + geoserver-data: + geo-db-data: + +services: + db: + image: kartoza/postgis:12.1 + restart: on-failure + healthcheck: + test: "exit 0" + + db-dbbackups: + build: + context: . + volumes: + - ./backups:/backups + environment: + - DUMPPREFIX=PG_gis + # List databases to back up; defaults to all + # Remove backups older than (in days) + - REMOVE_BEFORE=7 + - POSTGRES_HOST=db + - POSTGRES_DBNAME=gis + - POSTGRES_USER=docker + - POSTGRES_PASS=docker + - POSTGRES_PORT=5432 + # For restore script + - TARGET_DB=gis + - WITH_POSTGIS=1 + - TARGET_ARCHIVE=/backups/target_archive.dmp + restart: on-failure + depends_on: + db: + condition: service_healthy \ No newline at end of file diff --git a/start.sh b/start.sh index 12648ad..5829886 100755 --- a/start.sh +++ b/start.sh @@ -43,7 +43,7 @@ fi # How old can files and dirs be before getting trashed? In minutes if [ -z "${DBLIST}" ]; then - DBLIST=`psql -l | awk '$1 !~ /[+(|:]|Name|List|template|postgres/ {print $1}'` + DBLIST=`PGPASSWORD=${POSTGRES_PASS} psql -h $POSTGRES_HOST -p 5432 -U $POSTGRES_USER -l | awk '$1 !~ /[+(|:]|Name|List|template|postgres/ {print $1}'` fi # Now write these all to case file that can be sourced