From c4a20d523b5efdee746d1a1dee722ada4a2a00dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20M=C3=A1rquez?= Date: Fri, 20 Dec 2019 16:27:31 -0300 Subject: [PATCH] feat(makefile): add restore-from commands for pg_restore --- lib/potassium/assets/Makefile.erb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/potassium/assets/Makefile.erb b/lib/potassium/assets/Makefile.erb index 8c96199a..270dffc6 100644 --- a/lib/potassium/assets/Makefile.erb +++ b/lib/potassium/assets/Makefile.erb @@ -44,3 +44,18 @@ services-logs: services-port: @set -o pipefail; \ docker-compose $(DOCKER_COMPOSE_ARGS) port ${SERVICE} ${PORT} 2> /dev/null | cut -d':' -f2 || echo ${PORT} + +backup-staging: ROLE=staging +backup-production: ROLE=production +backup-%: + @echo Capturing $(ROLE).... + @heroku pg:backups:capture --remote $(ROLE) + +restore-from-staging: ROLE=staging +restore-from-production: ROLE=production +restore-from-%: + $(eval TEMP_FILE=$(shell mktemp)) + @echo Restoring from $(ROLE).... + @heroku pg:backups:download --remote $(ROLE) --output $(TEMP_FILE) + @pg_restore --verbose --clean --no-acl --no-owner -h localhost \ + -U postgres -p $(shell make services-port SERVICE=postgresql PORT=5432) -d $(PROJECT)_development $(TEMP_FILE)