tarback/tests/test-005-ssh-postgres.sh

52 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
set -eu
. ./tests/common.sh
export TARBACK_REMOTE='ssh localhost'
postgres_container_name="postgres-test-$(uuidgen)"
docker run --name "$postgres_container_name" -p 5432:5432 -e POSTGRES_PASSWORD=password123 -d postgres
trap "docker rm -f '$postgres_container_name'; exit" EXIT
for _ in $(seq 1 10); do
if echo '' | PGPASSWORD=password123 psql -h 10.1.0.100 -U postgres -p 5432 postgres; then
break
fi
sleep 1
done
PGPASSWORD=password123 psql -h 10.1.0.100 -U postgres -p 5432 postgres <<EOF
create table a(
i int
);
insert into a(i) values (1), (2), (3), (4);
EOF
d="$(mktemp -d)"
TARBACK_POSTGRES_ARGS='-h 10.1.0.100 -U postgres -p 5432 -w password123' ./tarback.sh -P ssh,postgres create postgres "$d/dump"
PGPASSWORD=password123 psql -h 10.1.0.100 -U postgres -p 5432 postgres <<EOF
insert into a(i) values (6), (7)
EOF
TARBACK_POSTGRES_ARGS='-h 10.1.0.100 -U postgres -p 5432 -w password123' ./tarback.sh -P ssh,postgres restore "$d/dump" postgres
out="$(PGPASSWORD=password123 psql -h 10.1.0.100 -U postgres -p 5432 postgres <<EOF
select i from a;
EOF
)"
out="$(echo "$out" | tail -n+3)"
expected_out="$(cat <<EOF
1
2
3
4
(4 rows)
EOF
)"
if [ "$out" != "$expected_out" ]; then
echo "$out" | xxd
echo "$expected_out" | xxd
exit 1
fi
rm -r "$d"