2024-02-22 13:39:54 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
. ./tests/common.sh
|
|
|
|
|
|
|
|
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)"
|
|
|
|
|
2024-02-22 14:22:20 +01:00
|
|
|
TARBACK_POSTGRES_ARGS='-h 10.1.0.100 -U postgres -p 5432 -w password123' ./tarback.sh -P postgres create postgres "$d/dump"
|
2024-02-22 13:39:54 +01:00
|
|
|
PGPASSWORD=password123 psql -h 10.1.0.100 -U postgres -p 5432 postgres <<EOF
|
|
|
|
insert into a(i) values (6), (7)
|
|
|
|
EOF
|
2024-02-22 14:22:20 +01:00
|
|
|
TARBACK_POSTGRES_ARGS='-h 10.1.0.100 -U postgres -p 5432 -w password123' ./tarback.sh -P postgres restore "$d/dump" postgres
|
2024-02-22 13:39:54 +01:00
|
|
|
|
|
|
|
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"
|