vars, enter psql in created db, and remove it at end
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 11 Sep 2021 13:06:32 +0000 (15:06 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 11 Sep 2021 13:24:22 +0000 (15:24 +0200)
wal-archive/restore.sh

index 3370274..983272b 100755 (executable)
@@ -1,19 +1,30 @@
 #!/bin/sh -xe
 
-dir=test-2021-09-11
+basebackup=test-2021-09-11
+restore=/tmp/r
 
-mkdir /tmp/r
-chown postgres:postgres /tmp/r
-chmod 700 /tmp/r
+mkdir $restore
+chown postgres:postgres $restore
+chmod 700 $restore
 
-tar xvf /tmp/test-2021-09-11/base.tar.gz -C /tmp/r/
-tar xvf /tmp/test-2021-09-11/pg_wal.tar.gz -C /tmp/r/pg_wal/
+tar xvf /tmp/test-2021-09-11/base.tar.gz -C $restore/
+tar xvf /tmp/test-2021-09-11/pg_wal.tar.gz -C $restore/pg_wal/
 
-cp /var/lib/pgsql/10/recovery.conf /tmp/r/
-vi /tmp/r/recovery.conf
+cp /var/lib/pgsql/10/recovery.conf $restore/
+vi $restore/recovery.conf
 
+cd $restore
 cat postgresql.conf | grep -v archive_mode | grep -v archive_command > postgresql.conf.new && mv postgresql.conf.new postgresql.conf
 
-su postgres -c '/usr/pgsql-10/bin/pg_ctl -D /tmp/r start -o "-p 5433"'
+su postgres -c '/usr/pgsql-10/bin/pg_ctl -D '$restore' start -o "-p 5433"'
 
-echo "STOP with: su postgres -c '/usr/pgsql-10/bin/pg_ctl -D /tmp/r stop'"
+cat > $restore.destroy << __SHELL__
+su postgres -c '/usr/pgsql-10/bin/pg_ctl -D $restore stop'
+rm -Rf $restore
+__SHELL__
+
+cd -
+psql -U postgres -p 5433
+
+su postgres -c '/usr/pgsql-10/bin/pg_ctl -D '$restore' stop'
+rm -Rf $restore