Skip to content

Commit a4e6e2d

Browse files
author
matthias_schaub
committed
Merge branch 'backup' into dev
2 parents 16d6574 + cf3dc14 commit a4e6e2d

File tree

11 files changed

+57
-68
lines changed

11 files changed

+57
-68
lines changed

docker-compose.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,35 +75,34 @@ services:
7575
POSTGERS_PASSWORD: '${POSTGRES_PASSWORD}'
7676
POSTGRES_USER: 'mapswipe_workers'
7777
POSTGRES_DB: 'mapswipe'
78+
PGDATA: '/var/lib/postgresql/mapswipe'
7879
WALG_GS_PREFIX: '${WALG_GS_PREFIX}'
7980
GOOGLE_APPLICATION_CREDENTIALS: '/serviceAccountKey.json'
8081
# Set options for WAL-G (backup tool)
8182
command: postgres -c archive_mode=on -c archive_timeout=60 -c archive_command="/archive_command.sh %p"
8283
volumes:
83-
- ./postgres-data:/var/lib/postgresql/data
84+
- ./postgres-data:/var/lib/postgresql/mapswipe
8485
restart: unless-stopped
8586
ports:
8687
- "5432:5432"
8788
networks:
8889
- postgres
8990

90-
postgres_restore_backup:
91-
container_name: postgres_restore_backup
91+
postgres_recovery:
92+
container_name: postgres_recovery
9293
build:
93-
context: postgres/
94-
dockerfile: Dockerfile-restore_backup
95-
args:
96-
WALG_GS_PREFIX: '${WALG_GS_PREFIX}'
97-
GOOGLE_APPLICATION_CREDENTIALS: '/serviceAccountKey.json'
94+
context: postgres/recovery/
9895
environment:
9996
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'
10097
POSTGRES_USER: 'mapswipe_workers'
10198
POSTGRES_DB: 'mapswipe'
102-
command: postgres
99+
PGDATA: '/var/lib/postgresql/mapswipe'
100+
WALG_GS_PREFIX: '${WALG_GS_PREFIX}'
101+
GOOGLE_APPLICATION_CREDENTIALS: '/serviceAccountKey.json'
103102
volumes:
104-
- ./postgres-data:/var/lib/postgresql/restored_cluster
103+
- ./pgdata_restored:/var/lib/postgresql/mapswipe
105104
ports:
106-
- "5432:5432"
105+
- "5445:5432"
107106

108107
firebase_deploy:
109108
container_name: firebase_deploy

postgres/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ COPY initdb.sql docker-entrypoint-initdb.d/
44
COPY serviceAccountKey.json serviceAccountKey.json
55

66
# Copy backup scripts and make them executable
7-
COPY wal-g/make_basebackup.sh make_basebackup.sh
8-
COPY wal-g/archive_command.sh archive_command.sh
7+
COPY backup/make_basebackup.sh make_basebackup.sh
8+
COPY backup/archive_command.sh archive_command.sh
99
RUN chmod +x make_basebackup.sh
1010
RUN chmod +x archive_command.sh
1111

12-
# Install wal-g (used by backup scripts)
12+
# Install wal-g (used by backup/recovery scripts)
1313
RUN apt-get update && apt-get install -y wget
1414
RUN wget https://github.com/wal-g/wal-g/releases/download/v0.2.9/wal-g.linux-amd64.tar.gz
1515
RUN tar -zxvf wal-g.linux-amd64.tar.gz

postgres/Dockerfile-restore_backup

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
export PGDATABSE=$POSTGRES_DB
3+
export PGDATABASE=$POSTGRES_DB
44
export PGUSER=$POSTGRES_USER
55
export PGPASSWORD=$POSTGRES_PASSWORD
66

Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
export PGDATABSE=$POSTGRES_DB
3+
export PGDATABASE=$POSTGRES_DB
44
export PGUSER=$POSTGRES_USER
55
export PGPASSWORD=$POSTGRES_PASSWORD
66

7-
wal-g backup-push /var/lib/postgresql/data
7+
wal-g backup-push /var/lib/postgresql/mapswipe

postgres/initdb.sql

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ CREATE TABLE IF NOT EXISTS results_temp (
102102
);
103103

104104
--
105-
-- USERS
105+
-- VIEWS
106106
--
107-
-- create a read-only user for backups
108-
CREATE USER backup WITH PASSWORD 'backupuserpassword';
109-
GRANT CONNECT ON DATABASE mapswipe TO backup;
110-
GRANT USAGE ON SCHEMA public TO backup;
111-
GRANT SELECT ON ALL TABLES IN SCHEMA public TO backup;
107+
-- create views for statistics
108+
\i /docker-entrypoint-initdb.d/stat_views.sql

postgres/recovery/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Based on latest stable postgres.
2+
FROM mdillon/postgis
3+
4+
COPY init_recovery.sh /usr/local/bin/
5+
COPY restore_command.sh .
6+
COPY recovery.conf .
7+
COPY serviceAccountKey.json .
8+
9+
RUN chmod +x /usr/local/bin/init_recovery.sh
10+
RUN chmod +x restore_command.sh
11+
12+
# Install wal-g (used by backup/restore scripts).
13+
RUN apt-get update && apt-get install -y wget
14+
RUN wget https://github.com/wal-g/wal-g/releases/download/v0.2.9/wal-g.linux-amd64.tar.gz
15+
RUN tar -zxvf wal-g.linux-amd64.tar.gz
16+
RUN mv wal-g /usr/local/bin/wal-g
17+
18+
# Restore base backup,
19+
# set user permissions and
20+
# copy recovery.conf into data cluster.
21+
ENTRYPOINT ["init_recovery.sh"]
22+
# Run default Postgres/PostGIS entrypoint and
23+
# start Postgres.
24+
CMD ["docker-entrypoint.sh", "postgres"]

postgres/recovery/init_recovery.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
# Restore base backup.
4+
# Will create a new Database Cluster.
5+
wal-g backup-fetch /var/lib/postgresql/mapswipe LATEST
6+
7+
# Move recovery.conf to cluster to tell postgres where to fetch WAL from.
8+
mv /recovery.conf /var/lib/postgresql/mapswipe/
9+
10+
chown -R postgres:postgres /var/lib/postgresql/mapswipe
11+
chmod 700 /var/lib/postgresql/mapswipe
12+
13+
# Execute command given in Dockerfile ("docker-entrypoint.sh", "postgres").
14+
exec "$@"

0 commit comments

Comments
 (0)