Skip to content

Commit

Permalink
fix backup script
Browse files Browse the repository at this point in the history
  • Loading branch information
NyakudyaA committed Apr 12, 2020
1 parent 140c558 commit ee629a3
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 36 deletions.
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
FROM kartoza/postgis:11.0-2.5
FROM kartoza/postgis:12.1
MAINTAINER [email protected]

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"]


2 changes: 1 addition & 1 deletion backups-cron
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
docker build -t kartoza/pg-backup:11.0 .
docker build -t kartoza/pg-backup:12.0 .
68 changes: 37 additions & 31 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ee629a3

Please sign in to comment.