# Define, check, create directories.
BACKUP_DIR="${BACKUP_ROOTDIR}/${YEAR}/${MONTH}/${DAY}"
TMP_DIR=
+LOGFILE="/dev/null"
#-------------------------------------------------------------------
detect_color() {
if [[ "${VERBOSE}" != "y" ]] ; then
return 0
fi
- echo -e " * [$(my_date)] [${BASENAME}:DEBUG]: $@" >&2
+ echo -e " * [$(my_date)] [${BASENAME}:DEBUG]: $@" | tee -a "${LOGFILE}"
}
#------------------------------------------------------------------------------
if [[ "${QUIET}" == "y" ]] ; then
return 0
fi
- echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASENAME}:${GREEN}INFO${NORMAL}] : $@" >&2
+ echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASENAME}:${GREEN}INFO${NORMAL}] : $@" | tee -a "${LOGFILE}"
}
#------------------------------------------------------------------------------
warn() {
- echo -e " ${YELLOW}*${NORMAL} [$(my_date)] [${BASENAME}:${YELLOW}WARN${NORMAL}] : $@" >&2
+ echo -e " ${YELLOW}*${NORMAL} [$(my_date)] [${BASENAME}:${YELLOW}WARN${NORMAL}] : $@" | tee -a "${LOGFILE}"
}
#------------------------------------------------------------------------------
error() {
- echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASENAME}:${RED}ERROR${NORMAL}]: $@" >&2
+ echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASENAME}:${RED}ERROR${NORMAL}]: $@" | tee -a "${LOGFILE}"
}
#------------------------------------------------------------------------------
if [[ "${VERBOSE}" == "y" ]] ; then
cmd+=" --verbose"
fi
- eval ${cmd} "$@"
+ eval ${cmd} "$@" 2>&1 | tee -a "${LOGFILE}"
}
#------------------------------------------------------------------------------
if [[ "${VERBOSE}" == "y" ]] ; then
cmd+=" --verbose"
fi
- eval ${cmd} "$@"
+ eval ${cmd} "$@" 2>&1 | tee -a "${LOGFILE}"
}
#------------------------------------------------------------------------------
if [[ "${VERBOSE}" == "y" ]] ; then
cmd+=" --verbose"
fi
- eval ${cmd} "$@"
+ eval ${cmd} "$@" 2>&1 | tee -a "${LOGFILE}"
}
#------------------------------------------------------------------------------
if [[ "${QUIET}" == "y" ]] ; then
return 0
fi
- echo
+ echo 2>&1 | tee -a "${LOGFILE}"
}
################################################################################
done
if [[ "${VERBOSE}" == "y" ]] ; then
- echo
- echo "Databases to backup:"
+ echo | tee -a "${LOGFILE}"
+ echo "Databases to backup:" | tee -a "${LOGFILE}"
for db in "${DATABASES[@]}" ; do
- echo " * '${db}'"
+ echo " * '${db}'" | tee -a "${LOGFILE}"
done
- echo
+ echo | tee -a "${LOGFILE}"
fi
}
MKDIR -p "${BACKUP_DIR}"
TMP_DIR=$( mktemp -d -p "${HOME}" backup.XXXXXXXX.d )
debug "Temporary directory is '${TMP_DIR}'."
+ LOGFILE="${BACKUP_DIR}/${TIMESTAMP}.log"
debug "Creating trap to cleanup temporary directory ..."
trap cleanup_tmp_dir INT TERM EXIT ABRT
fi
find "${BACKUP_ROOTDIR}" -type f -mtime +${KEEP_DAYS} -print0 | \
- xargs --null --no-run-if-empty rm ${verbose_option}
+ xargs --null --no-run-if-empty rm ${verbose_option} 2>&1 | tee -a "${LOGFILE}"
local year=
local month=
get_options "$@"
- get_databases
prepare_dirs
+ info "Starting backup ..."
+ get_databases
cleanup_old_backups
empty_line