Skip to content

Commit b8a825a

Browse files
committed
Rework write_log to not output more than it needs to
1 parent 2ccc867 commit b8a825a

File tree

1 file changed

+40
-58
lines changed

1 file changed

+40
-58
lines changed

install/assets/functions/10-db-backup

Lines changed: 40 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -112,32 +112,38 @@ bootstrap_variables() {
112112
if [ -n "${ENABLE_CHECKSUM}" ]; then
113113
print_warn "Deprecated and unsupported variable 'ENABLE_CHECKSUM' detected - Please upgrade your variables as they will be removed in version 4.3.0"
114114
if var_false "${ENABLE_CHECKSUM}" ; then
115+
sed -i "/DEFAULT_CHECKSUM=/d" "${backup_instance_vars}"
115116
echo "DEFAULT_CHECKSUM=NONE" >> "${backup_instance_vars}"
116117
fi
117118
fi
118119

119120
if [ -n "${DB_DUMP_BEGIN}" ]; then
120121
print_warn "Deprecated and unsupported variable 'DB_DUMP_BEGIN' detected - Please upgrade your variables as they will be removed in version 4.3.0"
122+
sed -i "/DEFAULT_BACKUP_BEGIN=/d" "${backup_instance_vars}"
121123
echo "DEFAULT_BACKUP_BEGIN=${DB_DUMP_BEGIN}" >> "${backup_instance_vars}"
122124
fi
123125

124126
if [ -n "${DB_DUMP_FREQ}" ]; then
125127
print_warn "Deprecated and unsupported variable 'DB_DUMP_FREQ' detected - Please upgrade your variables as they will be removed in version 4.3.0"
126-
echo "DEFAULT_BACKUP_INTERVAL=${DB_DUMP_INTERVAL}" >> "${backup_instance_vars}"
128+
sed -i "/DEFAULT_BACKUP_INTERVAL=/d" "${backup_instance_vars}"
129+
echo "DEFAULT_BACKUP_INTERVAL=${DB_DUMP_FREQ}" >> "${backup_instance_vars}"
127130
fi
128131

129132
if [ -n "${DB_DUMP_TARGET}" ]; then
130133
print_warn "Deprecated and unsupported variable 'DB_DUMP_TARGET' detected - Please upgrade your variables as they will be removed in version 4.3.0"
134+
sed -i "/DEFAULT_FILESYSTEM_PATH=/d" "${backup_instance_vars}"
131135
echo "DEFAULT_FILESYSTEM_PATH=${DB_DUMP_TARGET}" >> "${backup_instance_vars}"
132136
fi
133137

134138
if [ -n "${DB_DUMP_TARGET_ARCHIVE}" ]; then
135139
print_warn "Deprecated and unsupported variable 'DB_DUMP_TARGET_ACRHIVE' detected - Please upgrade your variables as they will be removed in version 4.3.0"
140+
sed -i "/DEFAULT_FILESYSTEM_ARCHIVE_PATH=/d" "${backup_instance_vars}"
136141
echo "DEFAULT_FILESYSTEM_ARCHIVE_PATH=${DB_DUMP_TARGET_ARCHIVE}" >> "${backup_instance_vars}"
137142
fi
138143

139144
if [ -n "${EXTRA_DUMP_OPTS}" ]; then
140145
print_warn "Deprecated and unsupported variable 'EXTRA_DUMP_OPTS' detected - Please upgrade your variables as they will be removed in version 4.3.0"
146+
sed -i "/DEFAULT_EXTRA_BACKUP_OPTS=/d" "${backup_instance_vars}"
141147
echo "DEFAULT_EXTRA_BACKUP_OPTS=${EXTRA_DUMP_OPTS}" >> "${backup_instance_vars}"
142148
fi
143149
##
@@ -159,10 +165,8 @@ bootstrap_variables() {
159165

160166
transform_backup_instance_variable "${backup_instance_number}" ARCHIVE_TIME backup_job_archive_time
161167
transform_backup_instance_variable "${backup_instance_number}" AUTH backup_job_db_auth
162-
set -x
163168
transform_backup_instance_variable "${backup_instance_number}" BACKUP_BEGIN backup_job_backup_begin
164169
transform_backup_instance_variable "${backup_instance_number}" BACKUP_INTERVAL backup_job_backup_interval
165-
set +x
166170
transform_backup_instance_variable "${backup_instance_number}" BACKUP_LOCATION backup_job_backup_location
167171
transform_backup_instance_variable "${backup_instance_number}" BLACKOUT_BEGIN backup_job_snapshot_blackout_start
168172
transform_backup_instance_variable "${backup_instance_number}" BLACKOUT_END backup_job_snapshot_blackout_finish
@@ -229,6 +233,7 @@ bootstrap_variables() {
229233
transform_backup_instance_variable "${backup_instance_number}" USER backup_job_db_user
230234

231235
backup_job_backup_begin=$(echo "${backup_job_backup_begin}" | sed -e "s|'||g" -e 's|"||g')
236+
rm -rf "${backup_instance_vars}"
232237
}
233238

234239
upgrade_lonely_variables() {
@@ -1753,70 +1758,47 @@ symlink_log () {
17531758

17541759
write_log() {
17551760
output_off
1756-
local CONTAINER_LOG_LEVEL_ORIGINAL=${CONTAINER_LOG_LEVEL}
17571761
local _arg_log_level=${1}
17581762
shift 1
17591763
local _arg_log_message="$@"
17601764

17611765
if [ -n "${backup_job_db_type}" ] && [ -n "${backup_job_db_name}" ] && [ -n "${backup_job_db_host}" ] && [ -n "${ltarget}" ]; then
1762-
write_to_file=true
1763-
else
1764-
write_to_file=false
1765-
fi
1766-
1767-
case "${_arg_log_level,,}" in
1768-
debug )
1769-
CONTAINER_LOG_LEVEL=DEBUG
1770-
case "${_arg_log_level,,}" in
1771-
"debug" )
1772-
print_debug "${_arg_log_message}"
1773-
if var_true "${write_to_file}" ; then
1766+
case "${_arg_log_level,,}" in
1767+
debug )
1768+
case "${_arg_log_level,,}" in
1769+
"debug" )
17741770
echo "$(date +'%Y-%m-%d %H:%M:%S %Z') [debug] ${_arg_log_message}" | run_as_user tee -a "${LOG_PATH}/$(date +'%Y%m%d')/$(date -d @${backup_job_start_time} +'%Y%m%d_%H%M%S')-${ltarget}.log" > /dev/null
1775-
fi
1776-
;;
1777-
esac
1778-
CONTAINER_LOG_LEVEL=${CONTAINER_LOG_LEVEL_ORIGINAL}
1779-
;;
1780-
error )
1781-
CONTAINER_LOG_LEVEL=ERROR
1782-
case "${_arg_log_level,,}" in
1783-
"debug" | "notice" | "warn" | "error")
1784-
print_error "${_arg_log_message}"
1785-
if var_true "${write_to_file}" ; then
1771+
;;
1772+
esac
1773+
;;
1774+
error )
1775+
case "${_arg_log_level,,}" in
1776+
"debug" | "notice" | "warn" | "error")
17861777
echo "$(date +'%Y-%m-%d %H:%M:%S %Z') [error] ${_arg_log_message}" | run_as_user tee -a "${LOG_PATH}/$(date +'%Y%m%d')/$(date -d @${backup_job_start_time} +'%Y%m%d_%H%M%S')-${ltarget}.log" > /dev/null
1787-
fi
1788-
;;
1789-
esac
1790-
;;
1791-
info )
1792-
CONTAINER_LOG_LEVEL=INFO
1793-
print_info "${_arg_log_message}"
1794-
if var_true "${write_to_file}" ; then
1778+
;;
1779+
esac
1780+
;;
1781+
info )
17951782
echo "$(date +'%Y-%m-%d %H:%M:%S %Z') [info] ${_arg_log_message}" | run_as_user tee -a "${LOG_PATH}/$(date +'%Y%m%d')/$(date -d @${backup_job_start_time} +'%Y%m%d_%H%M%S')-${ltarget}.log" > /dev/null
1796-
fi
1797-
;;
1798-
notice )
1799-
CONTAINER_LOG_LEVEL=NOTICE
1800-
case "${_arg_log_level,,}" in
1801-
"debug" | "notice" )
1802-
print_notice "${_arg_log_message}"
1803-
if var_true "${write_to_file}" ; then
1783+
;;
1784+
notice )
1785+
case "${_arg_log_level,,}" in
1786+
"debug" | "notice" )
18041787
echo "$(date +'%Y-%m-%d %H:%M:%S %Z') [notice] ${_arg_log_message}" | run_as_user tee -a "${LOG_PATH}/$(date +'%Y%m%d')/$(date -d @${backup_job_start_time} +'%Y%m%d_%H%M%S')-${ltarget}.log" > /dev/null
1805-
fi
1806-
;;
1807-
esac
1808-
;;
1809-
warn )
1810-
CONTAINER_LOG_LEVEL=WARN
1811-
case "${_arg_log_level,,}" in
1812-
"debug" | "notice" | "warn" )
1813-
print_warn "${_arg_log_message}"
1814-
if var_true "${write_to_file}" ; then
1788+
;;
1789+
esac
1790+
;;
1791+
warn )
1792+
case "${_arg_log_level,,}" in
1793+
"debug" | "notice" | "warn" )
18151794
echo "$(date +'%Y-%m-%d %H:%M:%S %Z') [warn] ${_arg_log_message}" | run_as_user tee -a "${LOG_PATH}/$(date +'%Y%m%d')/$(date -d @${backup_job_start_time} +'%Y%m%d_%H%M%S')-${ltarget}.log" > /dev/null
1816-
fi
1817-
;;
1818-
esac
1819-
;;
1820-
esac
1795+
;;
1796+
esac
1797+
;;
1798+
esac
1799+
1800+
fi
1801+
1802+
print_${_arg_log_level} "${_arg_log_message}"
18211803
output_on
18221804
}

0 commit comments

Comments
 (0)