|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -cat << EOF >> "$PGDATA/postgresql.conf" |
4 | | -wal_level = archive |
5 | | -archive_mode = on |
6 | | -archive_command = 'envdir "${WALG_ENVDIR}" wal-g wal-push %p' |
7 | | -archive_timeout = 60 |
8 | | -max_connections = 1024 |
9 | | -EOF |
10 | | - |
11 | | -# ensure $PGDATA has the right permissions |
12 | | -chown -R postgres:postgres "$PGDATA" |
13 | | -chmod 0700 "$PGDATA" |
14 | | - |
15 | | -# reboot the server for wal_level to be set before backing up |
16 | | -echo "Rebooting postgres to enable archive mode" |
17 | | -su-exec postgres pg_ctl -D "$PGDATA" -w restart |
18 | | - |
19 | 3 | # check if there are any backups -- if so, let's restore |
20 | 4 | # we could probably do better than just testing number of lines -- one line is just a heading, meaning no backups |
21 | 5 |
|
22 | 6 | if [[ $(envdir "$WALG_ENVDIR" wal-g backup-list | wc -l) -gt "1" ]]; then |
23 | 7 | echo "Found backups. Restoring from backup..." |
24 | | - su-exec postgres pg_ctl -D "$PGDATA" -w stop |
| 8 | + { |
| 9 | + su-exec postgres pg_ctl -D "$PGDATA" -w stop > /dev/null 2>&1 |
| 10 | + } || { |
| 11 | + echo "ignore script errors" |
| 12 | + } |
25 | 13 | rm -rf "$PGDATA" |
26 | 14 | envdir "$WALG_ENVDIR" wal-g backup-fetch "$PGDATA" LATEST |
27 | 15 | cat << EOF > "$PGDATA/postgresql.conf" |
|
56 | 44 | su-exec postgres pg_ctl -D "$PGDATA" \ |
57 | 45 | -o "-c listen_addresses=''" \ |
58 | 46 | -w start |
| 47 | +else |
| 48 | + cat << EOF >> "$PGDATA/postgresql.conf" |
| 49 | +wal_level = archive |
| 50 | +archive_mode = on |
| 51 | +archive_command = 'envdir "${WALG_ENVDIR}" wal-g wal-push %p' |
| 52 | +archive_timeout = 60 |
| 53 | +max_connections = 1024 |
| 54 | +EOF |
| 55 | + |
| 56 | + # ensure $PGDATA has the right permissions |
| 57 | + chown -R postgres:postgres "$PGDATA" |
| 58 | + chmod 0700 "$PGDATA" |
| 59 | + |
| 60 | + # reboot the server for wal_level to be set before backing up |
| 61 | + echo "Rebooting postgres to enable archive mode" |
| 62 | + su-exec postgres pg_ctl -D "$PGDATA" -w restart |
59 | 63 | fi |
60 | 64 |
|
61 | 65 | # ensure $PGDATA has the right permissions |
|
0 commit comments