diff --git a/client/zzz_evobackup b/client/zzz_evobackup index ba46469..0419cae 100755 --- a/client/zzz_evobackup +++ b/client/zzz_evobackup @@ -272,7 +272,7 @@ dump_mysql_global() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "mysqldump to ${dump_file} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - mysqldump to ${dump_file} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -298,7 +298,7 @@ dump_mysql_per_base() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "mysqldump to ${dump_file} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - mysqldump to ${dump_file} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -324,7 +324,7 @@ dump_mysql_meta() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "pt-show-grants to ${dump_file} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - pt-show-grants to ${dump_file} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -341,7 +341,7 @@ dump_mysql_meta() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "mysql 'show variables' returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - mysql 'show variables' returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -360,7 +360,7 @@ dump_mysql_meta() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "mysqldump to ${dump_file} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - mysqldump to ${dump_file} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -387,7 +387,7 @@ dump_mysql_tabs() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "mysqldump to ${dump_dir} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - mysqldump to ${dump_dir} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -414,7 +414,7 @@ dump_mysql_hotcopy() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "mysqlhotcopy to ${dump_dir} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - mysqlhotcopy to ${dump_dir} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -445,7 +445,7 @@ dump_mysql_instances() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "mysqldump to ${dump_file} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - mysqldump to ${dump_file} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -470,7 +470,7 @@ dump_postgresql_global() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "pg_dumpall to ${dump_file} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - pg_dumpall to ${dump_file} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -510,7 +510,7 @@ dump_postgresql_per_base() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "pg_dump to ${dump_file} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - pg_dump to ${dump_file} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -540,7 +540,7 @@ dump_postgresql_filtered() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "pg_dump to ${dump_file} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - pg_dump to ${dump_file} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -567,7 +567,7 @@ dump_redis() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "cp ${instance}/dump.rdb to ${dump_dir} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - cp ${instance}/dump.rdb to ${dump_dir} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -599,7 +599,7 @@ dump_mongodb() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "mongodump to ${dump_dir} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - mongodump to ${dump_dir} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -623,7 +623,7 @@ dump_megacli_config() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "megacli to ${dump_file} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - megacli to ${dump_file} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -676,7 +676,7 @@ dump_server_state() { dump_server_state_bin=$(command -v dump-server-state) if [ -z "${dump_server_state_bin}" ]; then - error "dump-server-state is missing" + log_error "LOCAL_TASKS - dump-server-state is missing" rc=1 else if [ "${SYSTEM}" = "linux" ]; then @@ -684,7 +684,7 @@ dump_server_state() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "dump-server-state returned an error ${last_rc}, check ${dump_dir}" + log_error "LOCAL_TASKS - dump-server-state returned an error ${last_rc}, check ${dump_dir}" rc=${E_DUMPFAILED} fi else @@ -692,7 +692,7 @@ dump_server_state() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "dump-server-state returned an error ${last_rc}, check ${dump_dir}" + log_error "LOCAL_TASKS - dump-server-state returned an error ${last_rc}, check ${dump_dir}" rc=${E_DUMPFAILED} fi fi @@ -716,7 +716,7 @@ dump_rabbitmq() { last_rc=$? # shellcheck disable=SC2086 if [ ${last_rc} -ne 0 ]; then - error "pg_dump to ${dump_file} returned an error ${last_rc}, check ${error_file}" + log_error "LOCAL_TASKS - pg_dump to ${dump_file} returned an error ${last_rc}" "${error_file}" rc=${E_DUMPFAILED} else rm -f "${error_file}" @@ -904,7 +904,7 @@ sync_tasks() { done < "${rsync_includes_file}" if [ "${#mtree_files[@]}" -le 0 ]; then - error "ERROR: mtree didn't produce any file" + log_error "SYNC_TASKS - ERROR: mtree didn't produce any file" fi log "SYNC_TASKS - stop mtree (files: ${mtree_files[*]})" @@ -966,7 +966,7 @@ sync_tasks() { # We ignore rc=24 (vanished files) if [ ${rsync_main_rc} -ne 0 ] && [ ${rsync_main_rc} -ne 24 ]; then - error "rsync returned an error ${rsync_main_rc}, check ${LOGFILE}" + log_error "SYNC_TASKS - rsync returned an error ${rsync_main_rc}" "${LOGFILE}" rc=${E_SYNCFAILED} else # Build the report Rsync command @@ -1007,13 +1007,29 @@ log() { "$(/bin/date +"${DATE_FORMAT}")" "${PROGNAME}" "${pid}" "${msg}" \ >> "${LOGFILE}" } -# Output a message to stderr -error() { - msg="${1:-$(cat /dev/stdin)}" - pid=$$ - printf "[%s] %s[%s]: %s\\n" \ - "$(/bin/date +"${DATE_FORMAT}")" "${PROGNAME}" "${pid}" "${msg}" \ - >&2 +log_error() { + error_msg=${1} + error_file=${2:""} + + if [ -n "${error_file}" ] && [ -f "${error_file}" ]; then + printf "\n### %s\n" "${error_msg}" >&2 + # shellcheck disable=SC2046 + if [ $(wc -l "${error_file}") -gt 30 ]; then + printf "~~~{%s (tail -30)}\n" "${error_file}" >&2 + tail -n 30 "${error_file}" >&2 + else + printf "~~~{%s}\n" "${error_file}" >&2 + cat "${error_file}" >&2 + fi + printf "~~~\n" >&2 + + log "${error_msg}, check ${error_file}" + else + printf "\n### %s\n" "${error_msg}" >&2 + + log "${error_msg}" + fi + } # Remove all temporary file created during the execution # shellcheck disable=SC2317