|
| 1 | +#!/bin/sh -ex |
| 2 | + |
| 3 | +# vars |
| 4 | +export PGVERSION=9.5.4 |
| 5 | +export PATH=$PATH:/usr/pgsql-9.5/bin |
| 6 | +export PGUSER=pgbench |
| 7 | +export PGDATABASE=pgbench |
| 8 | +export PGDATA=/var/lib/pgsql/9.5/data |
| 9 | +export BACKUP_PATH=/backups |
| 10 | +export ARCLOG_PATH=$BACKUP_PATH/backup/pg_xlog |
| 11 | +export PGDATA2=/var/lib/pgsql/9.5/data2 |
| 12 | +export PGBENCH_SCALE=100 |
| 13 | +export PGBENCH_TIME=60 |
| 14 | + |
| 15 | +# prepare directory |
| 16 | +cp -a /tests /build |
| 17 | +pushd /build |
| 18 | + |
| 19 | +# download postgresql |
| 20 | +yum install -y wget |
| 21 | +wget -k https://ftp.postgresql.org/pub/source/v$PGVERSION/postgresql-$PGVERSION.tar.gz -O postgresql.tar.gz |
| 22 | +tar xf postgresql.tar.gz |
| 23 | + |
| 24 | +# install pg_arman |
| 25 | +yum install -y https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm |
| 26 | +yum install -y postgresql95-devel make gcc readline-devel openssl-devel pam-devel libxml2-devel libxslt-devel |
| 27 | +make top_srcdir=postgresql-$PGVERSION |
| 28 | +make install top_srcdir=postgresql-$PGVERSION |
| 29 | + |
| 30 | +# initalize cluster and database |
| 31 | +yum install -y postgresql95-server |
| 32 | +su postgres -c "/usr/pgsql-9.5/bin/initdb -D $PGDATA -k" |
| 33 | +cat <<EOF > $PGDATA/pg_hba.conf |
| 34 | +local all all trust |
| 35 | +host all all 127.0.0.1/32 trust |
| 36 | +local replication pgbench trust |
| 37 | +host replication pgbench 127.0.0.1/32 trust |
| 38 | +EOF |
| 39 | +cat <<EOF > $PGDATA/postgresql.auto.conf |
| 40 | +max_wal_senders = 2 |
| 41 | +wal_level = logical |
| 42 | +wal_log_hints = on |
| 43 | +EOF |
| 44 | +su postgres -c "/usr/pgsql-9.5/bin/pg_ctl start -w -D $PGDATA" |
| 45 | +su postgres -c "createdb -U postgres $PGUSER" |
| 46 | +su postgres -c "createuser -U postgres -a -d -E $PGUSER" |
| 47 | +pgbench -i -s $PGBENCH_SCALE |
| 48 | + |
| 49 | +# Count current |
| 50 | +COUNT=$(psql -Atc "select count(*) from pgbench_accounts") |
| 51 | +pgbench -s $PGBENCH_SCALE -T $PGBENCH_TIME -j 2 -c 10 & |
| 52 | + |
| 53 | +# create backup |
| 54 | +pg_arman init |
| 55 | +pg_arman backup -b full --disable-ptrack-clear --stream -v |
| 56 | +pg_arman show |
| 57 | +sleep $PGBENCH_TIME |
| 58 | + |
| 59 | +# restore from backup |
| 60 | +chown -R postgres:postgres $BACKUP_PATH |
| 61 | +su postgres -c "pg_arman restore -D $PGDATA2" |
| 62 | + |
| 63 | +# start backup server |
| 64 | +su postgres -c "/usr/pgsql-9.5/bin/pg_ctl stop -w -D $PGDATA" |
| 65 | +su postgres -c "/usr/pgsql-9.5/bin/pg_ctl start -w -D $PGDATA2" |
| 66 | +( psql -Atc "select count(*) from pgbench_accounts" | grep $COUNT ) || (cat $PGDATA2/pg_log/*.log ; exit 1) |
0 commit comments