From ef5848f4ea923c2b705b4ce2d1837ecb5cc4fb1b Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 9 Jun 2019 17:08:15 +0200 Subject: [PATCH] Print additional infos about errors to std_out. --- conf/rcopy_functions.conf | 6 +++ hosts/scripts/dir_backup.sh | 1 + hosts/scripts/disksettings_backup.sh | 7 +++ hosts/scripts/mysql_backup.sh | 60 +++++++++++++++++++++---- hosts/scripts/net_mounted_dir_backup.sh | 6 +++ hosts/scripts/pgsql_backup.sh | 19 ++++++-- hosts/scripts/svn_backup.sh | 19 +++++++- rcopy.sh | 1 + 8 files changed, 105 insertions(+), 14 deletions(-) diff --git a/conf/rcopy_functions.conf b/conf/rcopy_functions.conf index 50d817c..62fc696 100644 --- a/conf/rcopy_functions.conf +++ b/conf/rcopy_functions.conf @@ -41,6 +41,12 @@ echononl(){ fi rm /tmp/shprompt$$ } + +print_error_stdout() { + echo -e -n "\n Host: ${srcHost}\n Error: $*" 1>&2 + echo "" +} + # # fatal(){ diff --git a/hosts/scripts/dir_backup.sh b/hosts/scripts/dir_backup.sh index 9b6792a..b5a58f6 100755 --- a/hosts/scripts/dir_backup.sh +++ b/hosts/scripts/dir_backup.sh @@ -212,6 +212,7 @@ if $MIRROR ;then if [ "$retval" = "24" ]; then echolog "\t[ Notice ] \"$real_backupSrcDir\": \n\t`$cat $err_Log`\n" else + print_error_stdout "Cannot mirror directory \"$real_backupSrcDir\"\n $(cat "$err_Log")" echolog "\t[ERROR] Cannot mirror directory \"$real_backupSrcDir\" [ $duration ]\n\t`$cat $err_Log`\n" fi else diff --git a/hosts/scripts/disksettings_backup.sh b/hosts/scripts/disksettings_backup.sh index f2a35d8..761ebb6 100755 --- a/hosts/scripts/disksettings_backup.sh +++ b/hosts/scripts/disksettings_backup.sh @@ -111,6 +111,7 @@ for _disk in $disks ; do if [ "$retval" = "0" ]; then echolog "\t--- \"info_${_disk}.txt\" successfully saved ---" else + print_error_stdout "Cannot save identification info for disk $disk:\n $(cat $err_Log)" echolog "\t[ERROR] Cannot save identification info for disk $disk: \n\t`$cat $err_Log`\n" fi fi @@ -158,6 +159,7 @@ for _disk in $disks ; do if [ "$retval" = "0" ]; then echolog "\t--- \"fdisk_${_disk}.txt\" successfully saved ---" else + print_error_stdout "Cannot save partition tables for $disk (info file):\n $(cat $err_Log)" echolog "\t[ERROR] Cannot save partition tables for $disk (info file): \n\t`$cat $err_Log`\n" fi fi @@ -185,6 +187,7 @@ for _disk in $disks ; do if [ "$retval" = "0" ]; then echolog "\t--- \"${_disk}.mbr\" successfully saved ---" else + print_error_stdout "Cannot save master boot record of disk $disk:\n $(cat $err_Log)" echolog "\t[ERROR] Cannot save master boot record of disk $disk: \n\t`$cat $err_Log`\n" fi else @@ -214,6 +217,7 @@ for _disk in $disks ; do if [ "$retval" = "0" ]; then echolog "\t--- \"${_disk}-partitions.sfdisk\" successfully saved ---" else + print_error_stdout "Cannot save partition table of disk $disk:\n $(cat $err_Log)" echolog "\t[ERROR] Cannot save partition table of disk $disk: \n\t`$cat $err_Log`\n" fi else @@ -252,6 +256,7 @@ for _disk in $disks ; do if [ "$retval" = "0" ]; then echolog "\t--- \"boot_sec-${_part}.bin\" successfully saved ---" else + print_error_stdout "Cannot save boot record of partition $partition:\n $(cat $err_Log)" echolog "\t[ERROR] Cannot save boot record of partition $partition: \n\t`$cat $err_Log`\n" fi else @@ -294,6 +299,7 @@ for _disk in $disks ; do if [ "$retval" = "0" ]; then echolog "\t--- \"fdisk_${_disk}.txt\" successfully saved ---" else + print_error_stdout "Cannot save partition tables for $disk (info file)\n $(cat $err_Log)" echolog "\t[ERROR] Cannot save partition tables for $disk (info file): \n\t`$cat $err_Log`\n" fi fi @@ -322,6 +328,7 @@ for _disk in $disks ; do if [ "$retval" = "0" ]; then echolog "\t--- \"${_disk}-partitions.sgdisk\" successfully saved ---" else + print_error_stdout "Cannot save partition table of disk $disk: \n $(cat $err_Log)" echolog "\t[ERROR] Cannot save partition table of disk $disk: \n\t`$cat $err_Log`\n" fi else diff --git a/hosts/scripts/mysql_backup.sh b/hosts/scripts/mysql_backup.sh index 5d0eaaf..7670810 100755 --- a/hosts/scripts/mysql_backup.sh +++ b/hosts/scripts/mysql_backup.sh @@ -118,24 +118,56 @@ fi # ------------------ Ende Variable ------------------ # # --------------------------------------------------- # - +err_msg="Determin existing databases failed" if [ $srcHost != "localhost" ] || $_via_ssh_tunnel ;then if [ -n "$mysql_credential_args" ] ; then - DATABASES=`$ssh ${ssh_user}@$srcHost "$mysql $mysql_credential_args -N -s -e \"show databases\""` - MYSQL_VERSION=`$ssh ${ssh_user}@$srcHost "$mysql $mysql_credential_args -N -s -e \"SELECT VERSION()\""` + DATABASES="$($ssh ${ssh_user}@$srcHost "$mysql $mysql_credential_args -N -s -e \"show databases\"" 2> $err_Log)" + retval=$? else - DATABASES=`$ssh ${ssh_user}@$srcHost "$mysql -u$mysql_user -p$mysql_password -N -s -e \"show databases\""` - MYSQL_VERSION=`$ssh ${ssh_user}@$srcHost "$mysql -u$mysql_user -p$mysql_password -N -s -e \"SELECT VERSION()\""` + DATABASES="$($ssh ${ssh_user}@$srcHost "$mysql -u$mysql_user -p$mysql_password -N -s -e \"show databases\"" 2> $err_Log)" + retval=$? fi else if [ -n "$mysql_credential_args" ] ; then - DATABASES=`$mysql $mysql_credential_args -N -s -e "show databases"` - MYSQL_VERSION=`$mysql $mysql_credential_args -N -s -e "SELECT VERSION()"` + DATABASES="$($mysql $mysql_credential_args -N -s -e "show databases" 2> $err_Log)" + retval=$? else - DATABASES=`$mysql -u$mysql_user -p$mysql_password -N -s -e "show databases"` - MYSQL_VERSION=`$mysql -u$mysql_user -p$mysql_password -N -s -e "SELECT VERSION()"` + DATABASES="$($mysql -u$mysql_user -p$mysql_password -N -s -e "show databases" 2> $err_Log)" + retval=$? fi fi +if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" + echolog "" + echolog "\t[ERROR] ${err_msg}\n\t $(cat $err_Log)\n" +fi + +err_msg="Determine version information about MySQL/MariaDB failed." +if [ $srcHost != "localhost" ] || $_via_ssh_tunnel ;then + if [ -n "$mysql_credential_args" ] ; then + MYSQL_VERSION="$($ssh ${ssh_user}@$srcHost "$mysql $mysql_credential_args -N -s -e \"SELECT VERSION()\"" 2> $err_Log)" + retval=$? + else + MYSQL_VERSION=`$ssh ${ssh_user}@$srcHost "$mysql -u$mysql_user -p$mysql_password -N -s -e \"SELECT VERSION()\""` + retval=$? + fi +else + if [ -n "$mysql_credential_args" ] ; then + MYSQL_VERSION="$($mysql $mysql_credential_args -N -s -e "SELECT VERSION()" 2> $err_Log)" + retval=$? + else + MYSQL_VERSION="$($mysql -u$mysql_user -p$mysql_password -N -s -e "SELECT VERSION()" 2> $err_Log)" + retval=$? + fi +fi +if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" + echolog "" + echolog "\t[ERROR] ${err_msg}\n\t $(cat $err_Log)\n" +fi + + + MYSQL_VERSION_NUM=`echo $MYSQL_VERSION | awk -F \. '{ printf "%02d", $1; printf "%02d", $2; printf "%02d", $3 }'` @@ -164,6 +196,7 @@ if $ARCHIVE ;then ## ----------------------------- ## - Backup SQL Grants for users ## - + found_errors=false info_msg="save SQL Grants for users" echononl "\t$info_msg" @@ -244,6 +277,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then @@ -362,6 +396,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then @@ -472,6 +507,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then @@ -583,6 +619,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then @@ -696,6 +733,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then @@ -805,6 +843,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then @@ -900,6 +939,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then @@ -1047,6 +1087,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then @@ -1198,6 +1239,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then diff --git a/hosts/scripts/net_mounted_dir_backup.sh b/hosts/scripts/net_mounted_dir_backup.sh index 7d882c0..a4b468e 100755 --- a/hosts/scripts/net_mounted_dir_backup.sh +++ b/hosts/scripts/net_mounted_dir_backup.sh @@ -19,6 +19,8 @@ if $mount_netdir ; then if [ $srcHost != "localhost" ] || $_via_ssh_tunnel ;then + print_error_stdout "Mounting network directories is only possible for localhost - yet:\n $(cat $err_Log)" + echolog "" echolog "\t[ERROR] Mounting network directories is only possible for localhost - yet" exit 1 else @@ -31,6 +33,8 @@ if $mount_netdir ; then sleep 5 if ! df | grep "$backup_dir" > /dev/null 2>&1 ;then + print_error_stdout "Cannot mount network directory to \"$backup_dir\":\n $(cat $err_Log)" + echolog "" echolog "\t[ERROR] Cannot mount network directory to \"$backup_dir\"" exit 1 fi @@ -49,6 +53,8 @@ backup_dir=$backup_dir $script_dir/dir_backup.sh if $mount_netdir ; then if [ $srcHost != "localhost" ];then + print_error_stdout "Mounting network directories is only possible for localhost - yet:\n $(cat $err_Log)" + echolog "" echolog "\t[ERROR] Mounting network directories is only possible for localhost - yet" exit 1 else diff --git a/hosts/scripts/pgsql_backup.sh b/hosts/scripts/pgsql_backup.sh index 7df867e..e75650a 100755 --- a/hosts/scripts/pgsql_backup.sh +++ b/hosts/scripts/pgsql_backup.sh @@ -54,11 +54,21 @@ if [ -z "$pg_dump" ]; then pg_dump="/usr/local/pgsql/bin/pg_dump" fi +err_msg="Determin existing databases failed" if [ $srcHost != "localhost" ] || $_via_ssh_tunnel ;then - DATABASES=`$ssh ${ssh_user}@$srcHost "$sudo -u $pgsql_user $psql -lt" \ - | $grep -v -e"^$" | $awk '{print$1}'` + + DATABASES="$($ssh ${ssh_user}@$srcHost "$sudo -u $pgsql_user $psql -lt" \ + | $grep -v -e"^$" | $awk '{print$1}' 2> /tmp/error)" + retval=$? + else - DATABASES=`$su - $pgsql_user -c "$psql -lt" | $grep -v -e"^$" | $awk '{print$1}'` + DATABASES="$($su - $pgsql_user -c "$psql -lt" | $grep -v -e"^$" | $awk '{print$1}' 2> /tmp/error)" + retval=$? +fi +if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" + echolog "" + echolog "\t[ERROR] ${err_msg}\n\t $(cat $err_Log)\n" fi @@ -131,6 +141,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then @@ -223,6 +234,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then @@ -324,6 +336,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then diff --git a/hosts/scripts/svn_backup.sh b/hosts/scripts/svn_backup.sh index a6b8d1e..94c6cf2 100755 --- a/hosts/scripts/svn_backup.sh +++ b/hosts/scripts/svn_backup.sh @@ -57,11 +57,25 @@ fi # ------------------ Ende Variable ------------------ # # --------------------------------------------------- # +err_msg="Determin existing SVN repositories failed" if [ $srcHost != "localhost" ] || $_via_ssh_tunnel ;then - _REPOSITORIES=`ssh ${ssh_user}@$srcHost "$sudo $find $svn_source_base_path -maxdepth 1 -type d -exec basename 'realpath {}' \;"` + #_REPOSITORIES=`ssh ${ssh_user}@$srcHost "$sudo $find $svn_source_base_path -maxdepth 1 -type d -exec basename 'realpath {}' \;"` + + _REPOSITORIES="$(ssh ${ssh_user}@$srcHost "$sudo $find $svn_source_base_path -maxdepth 1 -type d -exec basename 'realpath {}' \;" 2> /tmp/error)" + retval=$? + else - _REPOSITORIES=`find $svn_source_base_path -maxdepth 1 -type d -exec basename 'realpath {}' \;` + #_REPOSITORIES=`find $svn_source_base_path -maxdepth 1 -type d -exec basename 'realpath {}' \;` + + _REPOSITORIES="$(find $svn_source_base_path -maxdepth 1 -type d -exec basename 'realpath {}' \; 2> /tmp/error)" + retval=$? fi +if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" + echolog "" + echolog "\t[ERROR] ${err_msg}\n\t $(cat $err_Log)\n" +fi + for repos in $_REPOSITORIES ; do _dir=`basename $svn_source_base_path` @@ -142,6 +156,7 @@ if $ARCHIVE ;then ## - look about errors.. ## - if [ "$retval" != "0" ]; then + print_error_stdout "${err_msg}:\n $(cat $err_Log)" echolog "" echolog "\t[ERROR] ${err_msg} [ $duration ]\n\t`$cat $err_Log`\n" if ! $keep_backup_on_error ; then diff --git a/rcopy.sh b/rcopy.sh index 7f8b870..6ad6fae 100755 --- a/rcopy.sh +++ b/rcopy.sh @@ -237,6 +237,7 @@ fi ## - if $manual ; then host_scripts="${hosts_base_dir}/localhost.sh" + host_scripts="${hosts_base_dir}/srv-cityslang.cityslang.com.sh" else host_scripts=`$find $hosts_base_dir -maxdepth 1 -type f -perm -700 | $sort` fi