Skip to content

Commit

Permalink
Update Makefile and docker-compose.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
lucernae committed Oct 8, 2015
1 parent a6e84d7 commit 5ae62bb
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ deployment/pg/postgres_data/9.3
deployment/pg/postgres_staging_data/9.3
deployment/pg/postgres_dev_data/9.3
deployment/pg/dbbackup/
deployment/pg/sftp_backup/backups/
deployment/pg/sftp_backup/target/

# apt-cacher-ng
71-apt-cacher-ng
Expand Down
40 changes: 38 additions & 2 deletions deployment/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,16 @@ dbbackup:
@# - prefix causes command to continue even if it fails
docker exec -t -i $(PROJECT_ID)_dbbackup_1 /backups.sh
@docker exec -t -i $(PROJECT_ID)_dbbackup_1 cat /var/log/cron.log | tail -2 | head -1 | awk '{print $4}'
-@if [ -f "backups/latest.dmp" ]; then rm backups/latest.dmp; fi
-@docker exec -t -i $(PROJECT_ID)_dbbackup_1 /bin/sh -c "if [ -f /backups/latest.dmp ]; then echo 'remove symlink file'; rm /backups/latest.dmp; fi"
# backups is intentionally missing from front of first clause below otherwise symlink comes
# out with wrong path...
@ln -s `date +%Y`/`date +%B`/PG_$(PROJECT_ID)_gis.`date +%d-%B-%Y`.dmp backups/latest.dmp
@echo "creating a link in docker"
@docker exec -t -i $(PROJECT_ID)_dbbackup_1 /bin/sh -c "ln -s `date +%Y`/`date +%B`/PG_$(PROJECT_ID)_gis.`date +%d-%B-%Y`.dmp /backups/latest.dmp"
@echo "Backup should be at: backups/`date +%Y`/`date +%B`/PG_$(PROJECT_ID)_gis.`date +%d-%B-%Y`.dmp"
@echo "Copy backup for sftp-backup"
@docker exec -t -it $(PROJECT_ID)_dbbackup_1 /bin/sh -c "cp /backups/latest.dmp /target/latest.dmp"
# trigger sftp backups
@docker exec -t -i $(PROJECT_ID)_sftpbackup_1 /backups.sh

reload:
@echo
Expand Down Expand Up @@ -359,3 +364,34 @@ dev-qgis:
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$(DISPLAY) \
kartoza/qgis-desktop:latest; xhost -

dev-dbrestore:
@echo
@echo "------------------------------------------------------------------"
@echo "Restore dump from backups/latest.dmp in production mode"
@echo "------------------------------------------------------------------"
@# - prefix causes command to continue even if it fails
-@docker exec -t -i $(PROJECT_ID)dev_db_1 su - postgres -c "dropdb gis"
@docker exec -t -i $(PROJECT_ID)dev_db_1 su - postgres -c "createdb -O docker -T template_postgis gis"
@docker exec -t -i $(PROJECT_ID)dev_db_1 pg_restore /backups/latest.dmp | docker exec -i $(PROJECT_ID)dev_devdb_1 su - postgres -c "psql gis"

dev-dbbackup:
@echo
@echo "------------------------------------------------------------------"
@echo "Create `date +%d-%B-%Y`.dmp in production mode"
@echo "Warning: backups/latest.dmp will be replaced with a symlink to "
@echo "the new backup."
@echo "------------------------------------------------------------------"
@# - prefix causes command to continue even if it fails
docker exec -t -i $(PROJECT_ID)dev_devdbbackup_1 /backups.sh
@docker exec -t -i $(PROJECT_ID)dev_devdbbackup_1 cat /var/log/cron.log | tail -2 | head -1 | awk '{print $4}'
-@docker exec -t -i $(PROJECT_ID)dev_devdbbackup_1 /bin/sh -c "if [ -f /backups/latest.dmp ]; then echo 'remove symlink file'; rm /backups/latest.dmp; fi"
# backups is intentionally missing from front of first clause below otherwise symlink comes
# out with wrong path...
@echo "creating a link in docker"
@docker exec -t -i $(PROJECT_ID)dev_devdbbackup_1 /bin/sh -c "ln -s `date +%Y`/`date +%B`/PG_$(PROJECT_ID)_gis.`date +%d-%B-%Y`.dmp /backups/latest.dmp"
@echo "Backup should be at: backups/`date +%Y`/`date +%B`/PG_$(PROJECT_ID)_gis.`date +%d-%B-%Y`.dmp"
@echo "Copy backup for sftp-backup"
@docker exec -t -it $(PROJECT_ID)dev_devdbbackup_1 /bin/sh -c "cp /backups/latest.dmp /target/latest.dmp"
# trigger sftp backups
@docker exec -t -i $(PROJECT_ID)dev_devsftpbackup_1 /backups.sh
22 changes: 20 additions & 2 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ db: &db
- PASS=docker

dbbackup: &dbbackup
build: docker-backup
image: kartoza/pg-backup:9.3
hostname: pg-backups
volumes:
- ./pg/dbbackup/backups:/backups
- ./pg/sftp_backup/target:/target
links:
- db:db
environment:
Expand All @@ -48,11 +49,20 @@ dbbackup: &dbbackup
- PGPORT=5432
- PGHOST=db
- PGDATABASE=gis

sftpbackup: &sftpbackup
image: lucernae/sftp-backup
hostname: sftpbackup
volumes:
- ./pg/sftp_backup/backups:/backups
- ./pg/sftp_backup/target:/pg_backup
environment:
- DUMPPREFIX=PG_inasafedjango
- DAILY=14
- MONTHLY=12
- YEARLY=3
- TARGET_FOLDER=/pg_backup
env_file:
# SFTP Credential for backup service
- sftp_credential.env

uwsgi: &uwsgi
Expand All @@ -76,6 +86,7 @@ uwsgi: &uwsgi
- smtp:smtp
- db:db
- dbbackup:dbbackup
- sftpbackup:sftpbackup

web: &web
image: nginx
Expand Down Expand Up @@ -113,15 +124,22 @@ devdbbackup:
<<: *dbbackup
volumes:
- ./pg/dbbackup/devbackups:/backups
- ./pg/sftp_backup/target:/target
links:
- devdb:db

devsftpbackup:
<<: *sftpbackup
env_file:
- sftp_credential-dev.env

devuwsgi:
<<: *uwsgi
links:
- smtp:smtp
- devdb:db
- devdbbackup:dbbackup
- devsftpbackup:sftpbackup

devweb:
<<: *web
Expand Down
6 changes: 5 additions & 1 deletion deployment/sftp_credential.env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# copy this template as sftp_credential.env for production mode credential
# and as sftp_credential-dev.env for development mode credential
USE_SFTP_BACKUP=True
SFTP_HOST=localhost
SFTP_HOST=192.168.1.5
SFTP_USER=user
SFTP_PASSWORD=password
SFTP_DIR=/
TARGET_FOLDER=/pg_backup

0 comments on commit 5ae62bb

Please sign in to comment.