vars, enter psql in created db, and remove it at end
[edozvola] / wal-archive / restore.sh
1 #!/bin/sh -xe
2
3 basebackup=test-2021-09-11
4 restore=/tmp/r
5
6 mkdir $restore
7 chown postgres:postgres $restore
8 chmod 700 $restore
9
10 tar xvf /tmp/test-2021-09-11/base.tar.gz -C $restore/
11 tar xvf /tmp/test-2021-09-11/pg_wal.tar.gz -C $restore/pg_wal/
12
13 cp /var/lib/pgsql/10/recovery.conf $restore/
14 vi $restore/recovery.conf
15
16 cd $restore
17 cat postgresql.conf | grep -v archive_mode | grep -v archive_command > postgresql.conf.new && mv postgresql.conf.new postgresql.conf
18
19 su postgres -c '/usr/pgsql-10/bin/pg_ctl -D '$restore' start -o "-p 5433"'
20
21 cat > $restore.destroy << __SHELL__
22 su postgres -c '/usr/pgsql-10/bin/pg_ctl -D $restore stop'
23 rm -Rf $restore
24 __SHELL__
25
26 cd -
27 psql -U postgres -p 5433
28
29 su postgres -c '/usr/pgsql-10/bin/pg_ctl -D '$restore' stop'
30 rm -Rf $restore