pgsql_backup.sh: try to set PostgreSQL commands manually if they were not found.

This commit is contained in:
Christoph 2021-03-26 10:10:49 +01:00
parent 6693077cfd
commit 0b5978a3b1

View File

@ -40,18 +40,106 @@ if [ $srcHost != "localhost" ] || $_via_ssh_tunnel ;then
sudo=`$ssh ${ssh_user}@$srcHost which sudo`
su=`$ssh ${ssh_user}@$srcHost which su`
ssh_options="-o BatchMode=yes -o ConnectTimeout=360"
if [[ -z "$psql" ]] ; then
echolog ""
echolog "\t[WARN]: Cannot determin 'psql' command on remote host '$srcHost'."
psql="/usr/bin/psql"
echolog "\t Set 'psql' to '$psql' manually."
fi
if [[ -z "$pg_dump" ]] ; then
echolog ""
echolog "\t[WARN]: Cannot determin 'pg_dump' command on remote host '$srcHost'."
pg_dump="/usr/bin/pg_dump"
echolog "\t Set 'pg_dump' to '$pg_dump' manually."
fi
if [[ -z "$pg_dumpall" ]] ; then
echolog ""
echolog "\t[WARN]: Cannot determin 'pg_dumpall' command on remote host '$srcHost'."
pg_dumpall="/usr/bin/pg_dumpall"
echolog "\t Set 'pg_dumpall' to '$pg_dumpall' manually."
fi
if [[ -z "$sudo" ]] ; then
echolog ""
echolog "\t[WARN]: Cannot determin 'sudo' command on remote host '$srcHost'."
sudo="$(which sudo)"
[[ -z "$sudo" ]] && sudo="/usr/bin/sudo"
echolog "\t Set 'sudo' to '$sudo' manually."
fi
if [[ -z "$su" ]] ; then
echolog ""
echolog "\t[WARN]: Cannot determin 'su' command on remote host '$srcHost'."
su="$(which su)"
[[ -z "$su" ]] && su="/usr/bin/su"
echolog "\t Set 'su' to '$su' manually."
fi
else
psql=`which psql`
pg_dump=`which pg_dump`
pg_dumpall=`which pg_dumpall`
fi
psql="$(which psql)"
pg_dump="$(which pg_dump)"
pg_dumpall="$(which pg_dumpall)"
if [ -z "$psql" ]; then
psql="/usr/local/pgsql/bin/psql"
fi
if [[ -z "$psql" ]] ; then
echolog ""
echolog "\t[WARN]: Cannot determin 'psql' command on localhost. Try another way to determin it.."
if [[ -x "/usr/local/pgsql/bin/psql" ]] ; then
psql="/usr/local/pgsql/bin/psql"
elif [[ -x "/usr/bin/psql" ]] ; then
psql="/usr/bin/psql"
fi
if [[ -n "$psql" ]]; then
echolog "\t Found executable 'psql' command: $psql ."
else
print_error_stdout "Determin 'psql' command failed on localhost."
echolog ""
echolog "\t[ERROR] Determin 'psql' command failed on localhost."
fi
fi
if [[ -z "$pg_dump" ]] ; then
echolog ""
echolog "\t[WARN]: Cannot determin 'pg_dump' command on localhost. Try another way to determin it.."
if [[ -x "/usr/local/pgsql/bin/pg_dump" ]] ; then
pg_dump="/usr/local/pgsql/bin/pg_dump"
elif [[ -x "/usr/bin/pg_dump" ]] ; then
pg_dump="/usr/bin/pg_dump"
fi
if [[ -n "$pg_dump" ]]; then
echolog "\t Found executable 'pg_dump' command: $pg_dump ."
else
print_error_stdout "Determin 'pg_dump' command failed on localhost."
echolog ""
echolog "\t[ERROR] Determin 'pg_dump' command failed on localhost."
fi
fi
if [[ -z "$pg_dumpall" ]] ; then
echolog ""
echolog "\t[WARN]: Cannot determin 'pg_dumpall' command on localhost. Try another way to determin it.."
if [[ -x "/usr/local/pgsql/bin/pg_dumpall" ]] ; then
pg_dumpall="/usr/local/pgsql/bin/pg_dumpall"
elif [[ -x "/usr/bin/pg_dumpall" ]] ; then
pg_dumpall="/usr/bin/pg_dumpall"
fi
if [[ -n "$pg_dumpall" ]]; then
echolog "\t Found executable 'pg_dumpall' command: $pg_dumpall ."
else
print_error_stdout "Determin 'pg_dumpall' command failed on localhost."
echolog ""
echolog "\t[ERROR] Determin 'pg_dumpall' command failed on localhost."
fi
fi
if [ -z "$pg_dump" ]; then
pg_dump="/usr/local/pgsql/bin/pg_dump"
fi
err_msg="Determin existing databases failed"