2020-12-30 18:30:38 +01:00
|
|
|
load common
|
|
|
|
|
|
|
|
begin_pgsql() {
|
|
|
|
apt-get -qq install postgresql
|
2021-01-02 21:48:19 +01:00
|
|
|
systemctl is-active postgresql || systemctl start postgresql
|
2020-12-30 18:30:38 +01:00
|
|
|
sudo -u postgres createuser --superuser root
|
|
|
|
createdb bntest_p8Cz8k
|
|
|
|
createdb bntest_v11vJj
|
|
|
|
zcat "${BATS_TEST_DIRNAME}/samples/bntest_p8Cz8k.psql.gz" | psql -d bntest_p8Cz8k
|
|
|
|
zcat "${BATS_TEST_DIRNAME}/samples/bntest_v11vJj.psql.gz" | psql -d bntest_v11vJj
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_pgsql() {
|
|
|
|
cat << EOF > "${BATS_TMPDIR}/backup.d/test.pgsql"
|
|
|
|
databases = all
|
2021-01-05 16:41:44 +01:00
|
|
|
backupdir = ${BN_BACKUPDIR}/postgres
|
2020-12-30 18:30:38 +01:00
|
|
|
compress = yes
|
|
|
|
format = plain
|
|
|
|
EOF
|
|
|
|
|
|
|
|
chmod 0640 "${BATS_TMPDIR}/backup.d/test.pgsql"
|
|
|
|
}
|
|
|
|
|
|
|
|
finish_pgsql() {
|
|
|
|
dropdb bntest_p8Cz8k
|
|
|
|
dropdb bntest_v11vJj
|
|
|
|
sudo -u postgres dropuser root
|
2021-01-02 21:48:19 +01:00
|
|
|
systemctl stop postgresql
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown_pgsql() {
|
2021-01-05 16:41:44 +01:00
|
|
|
cleanup_backups local
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "plain: exports all databases, with compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases all
|
|
|
|
setconfig backup.d/test.pgsql compress yes
|
|
|
|
setconfig backup.d/test.pgsql format plain
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
gzip -tq "${BN_BACKUPDIR}/postgres/bntest0-all.sql.gz"
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "plain: exports all databases, without compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases all
|
|
|
|
setconfig backup.d/test.pgsql compress no
|
|
|
|
setconfig backup.d/test.pgsql format plain
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/postgres/bntest0-all.sql" ]
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "plain: exports specific database, with compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases bntest_v11vJj
|
|
|
|
setconfig backup.d/test.pgsql compress yes
|
|
|
|
setconfig backup.d/test.pgsql format plain
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql.gz"
|
|
|
|
[ "$(zgrep -c -e '^COPY' ${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql.gz)" -eq 68 ]
|
|
|
|
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.sql.gz" ]
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "plain: exports specific database, without compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases bntest_v11vJj
|
|
|
|
setconfig backup.d/test.pgsql compress no
|
|
|
|
setconfig backup.d/test.pgsql format plain
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql" ]
|
|
|
|
[ "$(grep -c -e '^COPY' ${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql)" -eq 68 ]
|
|
|
|
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.sql" ]
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "tar: exports all databases, with compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases all
|
|
|
|
setconfig backup.d/test.pgsql compress yes
|
|
|
|
setconfig backup.d/test.pgsql format tar
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz"
|
|
|
|
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
|
|
|
|
gzip -tq "${BN_BACKUPDIR}/postgres/globals.sql.gz"
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "tar: exports all databases, without compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases all
|
|
|
|
setconfig backup.d/test.pgsql compress no
|
|
|
|
setconfig backup.d/test.pgsql format tar
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
|
|
|
|
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
|
|
|
|
file ${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump | grep "POSIX tar archive"
|
|
|
|
file ${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump | grep "POSIX tar archive"
|
|
|
|
[ -s "${BN_BACKUPDIR}/postgres/globals.sql" ]
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "tar: exports specific database, with compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases bntest_v11vJj
|
|
|
|
setconfig backup.d/test.pgsql compress yes
|
|
|
|
setconfig backup.d/test.pgsql format tar
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
|
|
|
|
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz" ]
|
|
|
|
[ ! -e "${BN_BACKUPDIR}/postgres/globals.sql.gz" ]
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "tar: exports specific database, without compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases bntest_v11vJj
|
|
|
|
setconfig backup.d/test.pgsql compress no
|
|
|
|
setconfig backup.d/test.pgsql format tar
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
|
|
|
|
file ${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump | grep -q "POSIX tar archive"
|
|
|
|
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
|
|
|
|
[ ! -e "${BN_BACKUPDIR}/postgres/globals.sql" ]
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "custom: exports all databases, with compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases all
|
|
|
|
setconfig backup.d/test.pgsql compress yes
|
|
|
|
setconfig backup.d/test.pgsql format custom
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz"
|
|
|
|
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
|
|
|
|
gzip -tq "${BN_BACKUPDIR}/postgres/globals.sql.gz"
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "custom: exports all databases, without compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases all
|
|
|
|
setconfig backup.d/test.pgsql compress no
|
|
|
|
setconfig backup.d/test.pgsql format custom
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
|
|
|
|
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
|
|
|
|
file "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" | grep -q "PostgreSQL custom database dump"
|
|
|
|
file "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" | grep -q "PostgreSQL custom database dump"
|
|
|
|
[ -s "${BN_BACKUPDIR}/postgres/globals.sql" ]
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "custom: exports specific database, with compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases bntest_v11vJj
|
|
|
|
setconfig backup.d/test.pgsql compress yes
|
|
|
|
setconfig backup.d/test.pgsql format custom
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
|
|
|
|
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz" ]
|
|
|
|
[ ! -e "${BN_BACKUPDIR}/postgres/globals.sql.gz" ]
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "custom: exports specific database, without compression" {
|
|
|
|
setconfig backup.d/test.pgsql databases bntest_v11vJj
|
|
|
|
setconfig backup.d/test.pgsql compress no
|
|
|
|
setconfig backup.d/test.pgsql format custom
|
2021-01-05 16:41:44 +01:00
|
|
|
runaction test.pgsql
|
2020-12-31 22:40:14 +01:00
|
|
|
[ "$status" -eq 0 ]
|
2021-01-05 16:41:44 +01:00
|
|
|
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
|
|
|
|
file "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" | grep -q "PostgreSQL custom database dump"
|
|
|
|
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
|
|
|
|
[ ! -e "${BN_BACKUPDIR}/postgres/globals.sql" ]
|
2020-12-30 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|