diff --git a/tarback/postgres.sh b/tarback/postgres.sh index 70ff81f..012a76c 100644 --- a/tarback/postgres.sh +++ b/tarback/postgres.sh @@ -3,8 +3,9 @@ _tarback_plugin_postgres_host= _tarback_plugin_postgres_port= _tarback_plugin_postgres_user= +_tarback_plugin_postgres_password= -short_options='h:p:U:' +short_options='h:p:U:w:' while getopts "$short_options" arg; do case "$arg" in h) @@ -16,6 +17,9 @@ while getopts "$short_options" arg; do U) _tarback_plugin_postgres_user="$OPTARG" ;; + w) + _tarback_plugin_postgres_password="$OPTARG" + ;; esac done @@ -23,10 +27,11 @@ _tarback_plugin_postgres_command= [ -n "$_tarback_plugin_postgres_host" ] && _tarback_plugin_postgres_command="$_tarback_plugin_postgres_command -h '$_tarback_plugin_postgres_host'" [ -n "$_tarback_plugin_postgres_port" ] && _tarback_plugin_postgres_command="$_tarback_plugin_postgres_command -p '$_tarback_plugin_postgres_port'" [ -n "$_tarback_plugin_postgres_user" ] && _tarback_plugin_postgres_command="$_tarback_plugin_postgres_command -U '$_tarback_plugin_postgres_user'" -_tarback_plugin_postgres_create_command="pg_dump $_tarback_plugin_postgres_command "'"$1"' -_tarback_plugin_postgres_extract_command="psql $_tarback_plugin_postgres_command" +_tarback_plugin_postgres_create_command="PGPASSWORD='$_tarback_plugin_postgres_password' pg_dump --clean $_tarback_plugin_postgres_command "'"$1"' +_tarback_plugin_postgres_extract_command="PGPASSWORD='$_tarback_plugin_postgres_password' psql $_tarback_plugin_postgres_command" TARBACK_TAR_CREATE_COMMAND="$_tarback_plugin_postgres_create_command" TARBACK_TAR_EXTRACT_COMMAND="$_tarback_plugin_postgres_extract_command" TARBACK_EXTENSION='xz' TARBACK_TAR_CREATE_USE_ALT_COMMAND=false TARBACK_TAR_EXTRACT_USE_ALT_COMMAND=false + diff --git a/test.sh b/test.sh index 2cea390..fe7b06c 100755 --- a/test.sh +++ b/test.sh @@ -6,7 +6,9 @@ early_return="${TARBACK_TEST_EARLY_RETURN:-false}" failed=0 for f in ./tests/test-*.sh; do printf '%s' "Running test $f ... " - if "$f"; then + if "$f" 1>"$f.stdout.log" 2>"$f.stderr.log"; then + rm "$f.stdout.log" + rm "$f.stderr.log" echo "succeeded" else failed=$((failed+1)) @@ -15,6 +17,7 @@ for f in ./tests/test-*.sh; do break fi fi + find ./tests/ -type f -size 0 -delete done if [ $failed -ne 0 ]; then diff --git a/tests/test-004-postgres.sh b/tests/test-004-postgres.sh new file mode 100755 index 0000000..82b8627 --- /dev/null +++ b/tests/test-004-postgres.sh @@ -0,0 +1,51 @@ +#!/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 <