-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.sh
executable file
·108 lines (90 loc) · 2.9 KB
/
demo.sh
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
set -ex
## Until it is set up in teamcity (which requires merge to master)
## build the container with:
HERE=$(dirname $0)
(cd $HERE; ./teamcity-build.sh)
function assert_volume_missing() {
NAME=$1
if docker volume inspect $NAME > /dev/null 2>&1; then
echo "Volume $NAME already exists - remove with:"
echo " docker volume rm $NAME"
exit 1
fi
}
assert_volume_missing db_data
assert_volume_missing barman_data
assert_volume_missing barman_recover
docker volume create db_data
docker volume create barman_data
docker volume create barman_recover
docker network create pg_nw || true
function cleanup {
echo "Cleaning up"
set +e
docker stop db barman_container db_recovered
docker volume rm db_data barman_data barman_recover
docker network rm pg_nw
}
trap cleanup EXIT
docker run --rm -d \
--name db \
--network pg_nw \
-p 5435:5432 \
-v db_data:/pgdata \
vimc/montagu-db:master
docker exec db montagu-wait.sh
## This is something that needs to be done at the right place in each
## deployment.
docker exec db create-users.sh
## This will fit pretty happily into the general deployment approach
## that we have. This, in addition to setting barman's password, also
## creates the replication slot on the server if it is not there
## already.
docker exec db enable-replication.sh changeme changeme
## Or, put at least one transaction worth of data in:
docker run --rm --network=pg_nw \
vimc/montagu-migrate:master
## Get barman up
docker run -d --rm \
--name barman_container \
--network pg_nw \
-v barman_data:/var/lib/barman \
-v barman_recover:/recover \
vimc/montagu-barman:master
docker exec barman_container setup-barman
# If running noninteractively it seems to take barman a little time to
# get all the wal files in place. This was not an issue when I ran
# with the full montagu restore so might be an issue with very empty
# dbs?
sleep 60
docker exec barman_container barman list-backup all
docker exec barman_container recover-last
## Then try and use the instance:
docker run --rm -d \
--name db_recovered \
-v barman_recover:/pgdata \
vimc/montagu-db:master
docker exec db_recovered montagu-wait.sh
docker exec db_recovered \
psql -U vimc -d montagu -c \
"\dt"
## Again, but without the server running:
docker stop db
docker stop db_recovered
docker exec barman_container wipe-recover
docker stop barman_container
docker run --rm \
--entrypoint recover-last-no-server \
-v barman_data:/var/lib/barman \
-v barman_recover:/recover \
vimc/montagu-barman:master
docker run --rm -d \
--name db_recovered \
-v barman_recover:/pgdata \
vimc/montagu-db:master
docker exec db_recovered montagu-wait.sh
docker exec db_recovered \
psql -U vimc -d montagu -c \
"\dt"
docker stop db_recovered