diff --git a/backup.sh b/backup.sh index c9ddb85ed1dfdfbec8b7b0527994d86ec65af599..61ad8638385f533b1cdc0088448a84fe1ca4504f 100755 --- a/backup.sh +++ b/backup.sh @@ -17,8 +17,8 @@ # 2022-11-04 ah v1.2 rename hooks # ================================================================================ -. $( dirname "$0" )/jobhelper.sh -. `dirname $0`/inc_bash.sh +. $( dirname "$0" )/includes/jobhelper.sh +. `dirname $0`/includes/inc_bash.sh typeset -i rcBackup=0 typeset -i rcTransfer=0 diff --git a/check_clientbackup.sh b/check_clientbackup.sh index 1daec2aa320e52b7f096deaa44e7803a18a8c3d0..73d568840c87f49bed208a605bae4509e220b42e 100755 --- a/check_clientbackup.sh +++ b/check_clientbackup.sh @@ -20,7 +20,7 @@ # 2023-09-04 ah v1.6 fix perfdata dirs-del= # ============================================================================== -. $(dirname $0)/jobhelper.sh +. $(dirname $0)/includes/jobhelper.sh # ------------------------------------------------------------------------------ # CONFIG diff --git a/detector.sh b/detector.sh index 7c575744e7c5f953ff6f679511ea9bcc0a0d8d48..2eca8cf46f579a40cb014081dbf0bbe64050e8af 100755 --- a/detector.sh +++ b/detector.sh @@ -1,7 +1,7 @@ #!/bin/bash # ==================================================================== # -# P O C * Detect a database type +# Detect a database type # # -------------------------------------------------------------------- # ah: <www.axel-hahn.de> @@ -11,10 +11,12 @@ cd $( dirname $0 ) . vendor/ini.class.sh || exit 1 +. vendor/color.class.sh || exit 1 + . $(dirname $0)/includes/dbdetect.class.sh DBD_DEBUG=0 - +showInfos=0 USAGE="Detect profiles for databases which are located in $DBD_BASEDIR. @@ -24,15 +26,17 @@ This script helps you to define / verify custom profiles. SYNTAX: $( basename $0) [OPTIONS] [FILTER] OPTIONS: - -d|--debug show debug information - -h|--help Show this help + -h|--help Show this help + -i|--infos Show infos about detected profiles + -v|--verbose Show debug information during detection. This helps to find + out why a profile was skipped. PARAMETERS: FILTER a string / regex to filter profilenames. SXYNTAX: - $( basename $0) -d Test all profiles with debug output $( basename $0) mysql Test profiles matching 'mysql' only + $( basename $0) -v Test all profiles with debug output " # -------------------------------------------------------------------- @@ -40,36 +44,43 @@ SXYNTAX: # MAIN # ---------------------------------------------------------------------- -echo -echo " --==##| DATABASE PROFILE DETECTOR |##==-- " -echo +echo ';' >&2 +echo '; --==##| DATABASE PROFILE DETECTOR |##==-- ' +echo ';' >&2 -while [[ "$#" -gt 0 ]]; do case $1 in - -d|--debug) DBD_DEBUG=1;; +while [ "$#" -gt 0 ]; do case $1 in -h|--help) echo "$USAGE"; exit 0;; + -i|--infos) showInfos=1; shift 1;; + -v|--verbose) DBD_DEBUG=1; shift 1;; + *) if grep "^-" <<< "$1" >/dev/null ; then - echo; echo "ERROR: Unknown parameter: $1"; echo; _showHelp; exit 2 + echo; echo "ERROR: Unknown parameter: $1"; echo; echo "$USAGE"; exit 2 fi break; ;; esac; done +sFilter="${1:-.}" +test ! "${sFilter}" = "." && ( echo -n "Filter enabled: "; color.echo "blue" "${sFilter}"; echo ';' >&2) + dbdetect._wd "------" -for config in $(dbdetect.getConfigs | grep "${1:-.}"); do +for config in $(dbdetect.getConfigs | grep "${sFilter}"); do dbdetect._wd "----- $config" if dbdetect.exists $config; then - echo "FOUND: $config" - - echo " Type : $( dbdetect.getType $config )" - echo " Target dir : $( dbdetect.getProfile $config )" - echo " runas : $( dbdetect.runas )" - echo " Params : $( dbdetect.getParams )" - echo + color.print "green" "FOUND"; echo ": $config" + if [ "$showInfos" -gt "0" ]; then + echo " Type : $( dbdetect.getType $config )" + echo " Target dir : $( dbdetect.getProfile $config )" + echo " runas : $( dbdetect.runas )" + echo " Params : $( dbdetect.getParams )" + echo " Env : $( dbdetect.setenv )" + echo " Files : $( dbdetect.getFiles | grep -c '.' )" + echo ';' + fi else echo "SKIP : $config" fi dbdetect._wd done -echo # -------------------------------------------------------------------- diff --git a/includes/dbdetect.class.sh b/includes/dbdetect.class.sh index 2cdd781669aff0d45f4f2e5ac41d983eccfed4c9..1c33a5b7453028b9ec2f33452c16351778bc0978 100644 --- a/includes/dbdetect.class.sh +++ b/includes/dbdetect.class.sh @@ -6,6 +6,10 @@ # it analyzes all ini files with database profiles and sets # variables / environment to perform database backup/ restore # +# Remark: +# The script that sources this file must source vendor/ini.class.sh +# before using these functions. +# # ---------------------------------------------------------------------- # ====================================================================== @@ -24,13 +28,13 @@ declare -A DBD_PARAMS # write debug output if DBD_DEBUG is enabled # param string text to show function dbdetect._wd(){ - test "$DBD_DEBUG" -eq "1" && echo "DEBUG: $*" >&2 + test "$DBD_DEBUG" -ne "0" && color.echo "darkgray" "DEBUG: $*" >&2 } # get a list of all config files # param string full path of ini file function dbdetect.getConfigs(){ - find ${DBD_BASEDIR} -type f -name "*.ini" + find ${DBD_BASEDIR} -type f -name "*.ini" | sort } # get type from given ini file @@ -115,12 +119,16 @@ function dbdetect.exists(){ for myfile in $( ini.value "file[]" ) do if ! file -b "${myfile}" | grep -i "$filetype" >/dev/null; then - dbdetect._wd "... File ${myfile} is no type $filetype" + dbdetect._wd "... File ${myfile} is not of type $filetype" return 1 fi dbdetect._wd "... File ${myfile} is type $filetype" myfiles+="${myfile}|" done + if [ -z "${myfiles}" ]; then + dbdetect._wd "... No files for type [${filetype}] were added" + return 1 + fi fi # --- OK, everything was found ... we initialize it @@ -135,7 +143,7 @@ function dbdetect.exists(){ for mykey in su env params do value="$( ini.value "$mykey" )" - value="${value//\{\{tcp\}\}/$tcpport}" + value="${value//\{\{tcp-port\}\}/$tcpport}" value="${value//\{\{tcp-target\}\}/$tcptarget}" value="${value//\{\{dbuser\}\}/$dbuser}" value="${value//\{\{dbpassword\}\}/$dbpassword}" diff --git a/inc_bash.sh b/includes/inc_bash.sh similarity index 100% rename from inc_bash.sh rename to includes/inc_bash.sh diff --git a/jobhelper.sh b/includes/jobhelper.sh similarity index 100% rename from jobhelper.sh rename to includes/jobhelper.sh diff --git a/localdump.sh b/localdump.sh index d5e9334e126eded0b7c24e26ca2fad3fe85b9345..9d830a100eee30313c73233d34104984d875e6c9 100755 --- a/localdump.sh +++ b/localdump.sh @@ -31,10 +31,12 @@ # CONFIG VARS # ---------------------------------------------------------------------- + . $(dirname $0)/vendor/ini.class.sh + . $(dirname $0)/vendor/color.class.sh + + . $(dirname $0)/includes/jobhelper.sh + . $(dirname $0)/includes/inc_bash.sh | exit 1 - . $(dirname $0)/jobhelper.sh - . $(dirname $0)/inc_bash.sh - . $(dirname $0)/vendor/ini.class.sh . $(dirname $0)/includes/dbdetect.class.sh # if [ -r ~/.backup.conf ]; then diff --git a/restore.sh b/restore.sh index 3b1ce4dfd165c64009e7ebb06983d3251a818250..713adad9b6eba7055c4c3bfde7ab68b3d6cb9623 100755 --- a/restore.sh +++ b/restore.sh @@ -33,8 +33,8 @@ # . `dirname $0`/inc_config.sh - . $(dirname $0)/jobhelper.sh - . $(dirname $0)/inc_bash.sh + . $(dirname $0)/includes/jobhelper.sh + . $(dirname $0)/includes/inc_bash.sh # --- load a transfer plugin STORAGE_BIN=$(_j_getvar ${STORAGEFILE} "bin") diff --git a/transfer.sh b/transfer.sh index dd0c900a3884bfcb84d01839153ea468a4c2874a..9aa83357bd7fdcea1dfa2b499b507dc88d463295 100755 --- a/transfer.sh +++ b/transfer.sh @@ -48,8 +48,8 @@ # . `dirname $0`/inc_config.sh - . $(dirname $0)/jobhelper.sh - . $(dirname $0)/inc_bash.sh + . $(dirname $0)/includes/jobhelper.sh + . $(dirname $0)/includes/inc_bash.sh typeset -i rc=0 typeset -i doBackup=1