From f91b306d67493dd03b236e4136afc1112df7466f Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 16 Nov 2017 11:21:02 +0100 Subject: [PATCH] Adding detecting databases --- bin/backup_pgsql.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/bin/backup_pgsql.sh b/bin/backup_pgsql.sh index fc61b93..8a469c4 100755 --- a/bin/backup_pgsql.sh +++ b/bin/backup_pgsql.sh @@ -276,6 +276,33 @@ empty_line() { echo } +################################################################################ + +get_databases() { + + debug "Detecting databases to backup ..." + local db= + for db in $( psql --list \ + --tuples-only \ + --no-align \ + --no-readline \ + --expanded \ + --field-separator=',' | \ + grep -i '^Name' | \ + awk -F ',' '{print $2}' ) ; do + DATABASES+=( "${db}" ) + done + + if [[ "${VERBOSE}" == "y" ]] ; then + echo + echo "Databases to backup:" + for db in "${DATABASES[@]}" ; do + echo " * '${db}'" + done + fi + +} + ################################################################################ ## ## Main @@ -287,6 +314,7 @@ main() { get_options "$@" + get_databases empty_line info "Finished." -- 2.39.5