From 3609950922f781ddeaf73df52e339938c68c70d5 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 20 Apr 2021 14:09:36 +0200 Subject: [PATCH] Making output better. --- bin/manual-backup | 14 +++++++++++-- lib/functions.rc | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/bin/manual-backup b/bin/manual-backup index 3283ae3..225c88c 100755 --- a/bin/manual-backup +++ b/bin/manual-backup @@ -111,7 +111,7 @@ eval_my_options() { if [[ "${#REMOTE_HOSTS[*]}" == "0" ]] ; then debug "No remote host for mirroring given." else - debug "Remote hosts for mirroring: ${CYAN}${REMOTE_HOSTS[*]}" + debug "Remote hosts for mirroring: ${CYAN}${REMOTE_HOSTS[*]}${NORMAL}" fi } @@ -216,7 +216,7 @@ do_dir_backup() { local odir= local odir_base= - info "Starting Backup ..." + info "Starting directory backup ..." MKDIR -p "${BACKUP_DIR}" @@ -387,6 +387,11 @@ sync_to_remote() { cmd+=" --verbose" fi cmd+=" \"${BACKUP_HOSTDIR}\" \"${rhost}:${BACKUP_PARENTDIR}\"" + if [[ "${QUIET}" == "y" ]] ; then + cmd+=" >> \"${LOGFILE}\" 2>&1" + else + cmd+=" 2>&1 | tee -a \"${LOGFILE}\"" + fi if [[ "${SIMULATE}" == "y" ]] ; then info "Executing: ${cmd}" continue @@ -404,6 +409,11 @@ main() { get_options "$@" umask 0022 + empty_line + dline + info "Starting manual backup of host '${GREEN}$( hostname -f )${NORMAL}'." + empty_line + check_preferences do_dir_backup do_mysql_backup diff --git a/lib/functions.rc b/lib/functions.rc index e6db32f..89d6900 100644 --- a/lib/functions.rc +++ b/lib/functions.rc @@ -319,6 +319,57 @@ error() { echo -e " ${RED}*${NORMAL} [${ts}] [${BASE_NAME}:${RED}ERROR${NORMAL}]: $@" >&2 } +#------------------------------------------------------------------------------ +line() { + + local lchar='-' + if [[ "$#" -ge 1 ]] ; then + lchar=$( echo "$1" | sed -e 's/^\(.\).*/\1/' ) + fi + + local count=79 + if [[ "$#" -ge 2 ]] ; then + count="$2" + fi + + local i=0 + local l='' + + while [[ "$i" -lt "${count}" ]] ; do + l+="${lchar}" + i=$(( $i + 1 )) + done + + if [[ -n "${LOGFILE}" ]] ; then + echo "${l}" >>"${LOGFILE}" + fi + + if [[ "${QUIET}" == "y" ]] ; then + return + fi + echo "${l}" + +} + +#------------------------------------------------------------------------------ +dline() { + line '=' "$@" +} + +#------------------------------------------------------------------------------ +empty_line() { + + if [[ -n "${LOGFILE}" ]] ; then + echo >>"${LOGFILE}" + fi + + if [[ "${QUIET}" == "y" ]] ; then + return + fi + echo + +} + #------------------------------------------------------------------------------ RM() { -- 2.39.5