Revision 3393
Added by Aaron Marcuse-Kubitza over 12 years ago
backups/Makefile | ||
---|---|---|
1 |
##### Vars/functions |
|
2 |
|
|
3 |
# Paths |
|
4 |
bin := ../bin |
|
5 |
|
|
6 |
# Terminal |
|
7 |
esc := '[' |
|
8 |
reset := $(esc)'0m' |
|
9 |
emph := $(esc)'7m ' |
|
10 |
endEmph := ' '$(reset) |
|
11 |
|
|
12 |
# User interaction |
|
13 |
|
|
14 |
confirm = $(if $(shell read -p $(emph)"$(1)"$(endEmph)$$'$(if\ |
|
15 |
$(2),\n$(2))\nContinue? (y/n) ' REPLY; test "$$REPLY" = y && echo t),,\ |
|
16 |
$(error Aborting)) |
|
17 |
|
|
18 |
# DB |
|
19 |
psqlVerbose := $(bin)/psql_script_vegbien --echo-all |
|
20 |
pg_dump := $(bin)/pg_dump_vegbien |
|
21 |
rmSchema = 'DROP SCHEMA IF EXISTS "$(1)" CASCADE;' |
|
22 |
|
|
23 |
##### General targets |
|
24 |
|
|
25 |
all: |
|
26 |
|
|
27 |
.SUFFIXES: # turn off built-in suffix rules |
|
28 |
.SECONDARY: # don't automatically delete intermediate files |
|
29 |
.DELETE_ON_ERROR: # delete target if recipe fails |
|
30 |
|
|
31 |
_always: |
|
32 |
.PHONY: _always |
|
33 |
|
|
34 |
##### Backups |
|
35 |
|
|
36 |
# Note: This can't be used for the current (unrotated) public schema because |
|
37 |
# pg_dump doesn't back up the CREATE SCHEMA statement for it, assuming falsely |
|
38 |
# that public already exists because it's in template1. |
|
39 |
%.backup %.sql: |
|
40 |
"time" env data=1 $(if $(filter %.sql,$@),plain=1) $(pg_dump) $* >$@ |
|
41 |
|
|
42 |
restore := "time" $(bin)/postgres_vegbien pg_restore --exit-on-error --verbose |
|
43 |
restoreBien := $(restore) --dbname=vegbien |
|
44 |
# pg_restore doesn't support PGDATABASE env var |
|
45 |
|
|
46 |
%/restore: % _always |
|
47 |
$(restoreBien) $< &>$<.log |
|
48 |
|
|
49 |
%.sql: % |
|
50 |
$(restore) $< >$@ 2>$<.extract.log |
|
51 |
|
|
52 |
##### Archived imports |
|
53 |
|
|
54 |
confirmRm = $(call confirm,WARNING: This will delete the archived import $(1)!) |
|
55 |
|
|
56 |
%.backup/remove: %.backup _always |
|
57 |
@$(call confirmRm,$*) |
|
58 |
echo $(call rmSchema,$*)|$(bin)/psql_script_vegbien |
|
59 |
|
|
60 |
%.backup/rm_indexes: %.backup _always |
|
61 |
$(pg_dump) $*|$(bin)/mk_rm_indexes|$(psqlVerbose) |
README.TXT | ||
---|---|---|
17 | 17 |
Note: This will archive the last import. |
18 | 18 |
|
19 | 19 |
Maintenance of archived imports: |
20 |
Back up: make schemas/public.<date>.backup &
|
|
20 |
Back up: make backups/public.<date>.backup &
|
|
21 | 21 |
Note: To back up the last import, you must archive it first (see above) |
22 |
Restore: make schemas/public.<date>.backup/restore &
|
|
23 |
Remove: make schemas/public.<date>/uninstall
|
|
22 |
Restore: make backups/public.<date>.backup/restore &
|
|
23 |
Remove: make backups/public.<date>.backup/remove
|
|
24 | 24 |
|
25 | 25 |
Datasource setup: |
26 | 26 |
Add a new datasource: make inputs/<short_name>/add |
Makefile | ||
---|---|---|
243 | 243 |
-<$< $(psqlAsBien) |
244 | 244 |
# ignore errors if schema exists |
245 | 245 |
|
246 |
# /%.backup must come before /% to be matched first |
|
247 |
schemas/%.backup/uninstall schemas/%/uninstall: _always |
|
246 |
schemas/%/uninstall: _always |
|
248 | 247 |
echo $(call rmSchemaCmd,$*)|$(psqlAsBien) |
249 | 248 |
|
250 |
# Note: This can't be used for the current (unrotated) public schema because |
|
251 |
# pg_dump doesn't back up the CREATE SCHEMA statement for it, assuming falsely |
|
252 |
# that public already exists because it's in template1. |
|
253 |
schemas/%.backup: |
|
254 |
"time" env data=1 bin/pg_dump_vegbien $* >$@ |
|
255 |
|
|
256 |
restore := "time" bin/postgres_vegbien pg_restore --exit-on-error --verbose |
|
257 |
restoreBien := $(restore) --dbname=vegbien |
|
258 |
# pg_restore doesn't support PGDATABASE env var |
|
259 |
|
|
260 |
schemas/%.backup/restore: schemas/%.backup _always |
|
261 |
$(restoreBien) $< &>$<.log |
|
262 |
|
|
263 |
schemas/%.sql: schemas/%.backup |
|
264 |
$(restore) $< >$@ 2>$<.extract.log |
|
265 |
|
|
266 |
schemas/%/rm_indexes: _always |
|
267 |
bin/pg_dump_vegbien $*|bin/mk_rm_indexes|$(psqlAsBien) --echo-all |
|
268 |
|
|
269 | 249 |
# Needed on Ubuntu 12.04 (also other Linuxes?) because %/reinstall is ignored. |
270 | 250 |
schemas/temp/reinstall: _always schemas/temp/uninstall schemas/temp/install ; |
271 | 251 |
|
Also available in: Unified diff
Moved archived imports and make targets to maintain them to new backups dir