1 |
6522
|
aaronmk
|
selfDir_NzrNZp := $(dir $(lastword $(MAKEFILE_LIST)))
|
2 |
|
|
root := $(selfDir_NzrNZp)..
|
3 |
|
|
include $(root)/lib/common.Makefile
|
4 |
3699
|
aaronmk
|
|
5 |
|
|
|
6 |
3393
|
aaronmk
|
##### Vars/functions
|
7 |
|
|
|
8 |
3403
|
aaronmk
|
# Make
|
9 |
|
|
SHELL := /bin/bash
|
10 |
|
|
|
11 |
3438
|
aaronmk
|
# Paths
|
12 |
6522
|
aaronmk
|
bin := $(root)/bin
|
13 |
3438
|
aaronmk
|
|
14 |
3393
|
aaronmk
|
# DB
|
15 |
7024
|
aaronmk
|
psqlNoSearchPath := env no_search_path=1 $(bin)/psql_script_vegbien
|
16 |
3393
|
aaronmk
|
pg_dump := $(bin)/pg_dump_vegbien
|
17 |
3404
|
aaronmk
|
backup := "time" env data=1 $(pg_dump)
|
18 |
|
|
restore := "time" $(bin)/postgres_vegbien pg_restore --exit-on-error
|
19 |
|
|
restoreBien := $(restore) --dbname=vegbien
|
20 |
|
|
# pg_restore doesn't support PGDATABASE env var
|
21 |
3393
|
aaronmk
|
|
22 |
3437
|
aaronmk
|
##### Backups
|
23 |
3393
|
aaronmk
|
|
24 |
6526
|
aaronmk
|
backups := $(wildcard *.backup)
|
25 |
|
|
|
26 |
6571
|
aaronmk
|
#### Checksums
|
27 |
|
|
|
28 |
6526
|
aaronmk
|
md5s: _always $(backups:%=%.md5) ;
|
29 |
|
|
|
30 |
6571
|
aaronmk
|
#### SQL
|
31 |
|
|
|
32 |
6520
|
aaronmk
|
# Must come before %.sql with no prerequisites to be matched first
|
33 |
3395
|
aaronmk
|
%.sql: %
|
34 |
3399
|
aaronmk
|
$(restore) $< >$@
|
35 |
3395
|
aaronmk
|
|
36 |
4751
|
aaronmk
|
# Full DB
|
37 |
|
|
# Must come before %.backup to be matched first
|
38 |
|
|
vegbien.%.backup:
|
39 |
|
|
$(backup) all >$@
|
40 |
6648
|
aaronmk
|
$(MAKE) $@.md5
|
41 |
4751
|
aaronmk
|
|
42 |
3544
|
aaronmk
|
backup* = $(backup) $* >$@
|
43 |
|
|
|
44 |
3393
|
aaronmk
|
# Note: This can't be used for the current (unrotated) public schema because
|
45 |
|
|
# pg_dump doesn't back up the CREATE SCHEMA statement for it, assuming falsely
|
46 |
|
|
# that public already exists because it's in template1.
|
47 |
3543
|
aaronmk
|
%.backup:
|
48 |
|
|
$(backup*)
|
49 |
6521
|
aaronmk
|
$(MAKE) $@.md5
|
50 |
3544
|
aaronmk
|
|
51 |
|
|
# When testing, turn off %.sql so make won't skip `%.sql: %` in favor of it
|
52 |
|
|
ifeq ($(filter %.backup/test,$(MAKECMDGOALS)),)
|
53 |
3543
|
aaronmk
|
%.sql:
|
54 |
|
|
env plain=1 $(backup*)
|
55 |
3544
|
aaronmk
|
endif
|
56 |
3393
|
aaronmk
|
|
57 |
3402
|
aaronmk
|
%.backup/restore: %.backup _always
|
58 |
3399
|
aaronmk
|
$(restoreBien) $<
|
59 |
3393
|
aaronmk
|
|
60 |
3402
|
aaronmk
|
%.sql/restore: %.sql _always
|
61 |
|
|
$(bin)/psql_script_vegbien <$<
|
62 |
|
|
# pg_restore only supports "non-plain-text formats"
|
63 |
|
|
# (http://www.postgresql.org/docs/9.1/static/app-pgrestore.html)
|
64 |
|
|
|
65 |
3409
|
aaronmk
|
%.backup/test: %.backup.sql _always
|
66 |
|
|
rm $<
|
67 |
|
|
|
68 |
3437
|
aaronmk
|
#### Archived imports
|
69 |
3393
|
aaronmk
|
|
70 |
|
|
confirmRm = $(call confirm,WARNING: This will delete the archived import $(1)!)
|
71 |
|
|
|
72 |
6940
|
aaronmk
|
public* = $(*:vegbien.%=%)
|
73 |
6645
|
aaronmk
|
|
74 |
3393
|
aaronmk
|
%.backup/remove: %.backup _always
|
75 |
6645
|
aaronmk
|
@$(call confirmRm,$(public*))
|
76 |
7024
|
aaronmk
|
echo $(call rmSchemaCmd,$(public*))|$(psqlNoSearchPath)
|
77 |
3393
|
aaronmk
|
|
78 |
3701
|
aaronmk
|
##### Synchronization
|
79 |
|
|
|
80 |
6469
|
aaronmk
|
rsyncBackups := $(rsync) --include="/*.backup" --include="/*.sql"\
|
81 |
6595
|
aaronmk
|
--include="/*.csv" --include="/*.md5" --exclude="**"
|
82 |
3701
|
aaronmk
|
|
83 |
|
|
upload: _always
|
84 |
10027
|
aaronmk
|
$(bin)/sync_upload './**'
|
85 |
6667
|
aaronmk
|
|
86 |
|
|
%/download: _always
|
87 |
7037
|
aaronmk
|
-$(if $(filter %.md5,$*),,$(MAKE) $*.md5/download)
|
88 |
6667
|
aaronmk
|
$(rsync) $(remote)$* $(local)$*
|
89 |
6724
|
aaronmk
|
# ignore errors if $*.md5 does not exist
|