-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
35 lines (28 loc) · 1.08 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
PROJECT ?= alpine-rails
SHELL := /bin/bash
run: help
BOLD ?= $(shell tput bold)
NORMAL ?= $(shell tput sgr0)
help:
@echo "Generate a backup in the environment (staging|production) database:"
@echo " ${BOLD}make backup-<environment>${NORMAL}"
@echo ""
@echo "Copy latest database backup from the environment (staging|production) to local database:"
@echo " ${BOLD}make restore-from-<environment>${NORMAL}"
@echo ""
services-port:
@set -o pipefail; \
docker-compose 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)