Add source name tag in log line

This commit is contained in:
Darko Poljak 2018-09-20 16:08:00 +02:00
parent 51f468182f
commit 420dc3fe7f
2 changed files with 28 additions and 26 deletions

View file

@ -514,6 +514,7 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
c_dest="${backup}/destination" c_dest="${backup}/destination"
c_pre_exec="${backup}/pre_exec" c_pre_exec="${backup}/pre_exec"
c_post_exec="${backup}/post_exec" c_post_exec="${backup}/post_exec"
tag="[${name}]"
# #
# Stderr to stdout, so we can produce nice logs # Stderr to stdout, so we can produce nice logs
@ -524,13 +525,13 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
# Record start of backup: internal and for the user # Record start of backup: internal and for the user
# #
begin_s="$(${SDATE})" begin_s="$(${SDATE})"
_techo "Beginning to backup" _techo "${tag}" "Beginning to backup"
# #
# Standard configuration checks # Standard configuration checks
# #
if [ ! -e "${backup}" ]; then if [ ! -e "${backup}" ]; then
_exit_err "Source does not exist." _exit_err "Source \"${backup}\" does not exist."
fi fi
# #
@ -554,11 +555,11 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
# First execute pre_exec, which may generate destination or other parameters # First execute pre_exec, which may generate destination or other parameters
# #
if [ -x "${c_pre_exec}" ]; then if [ -x "${c_pre_exec}" ]; then
_techo "Executing ${c_pre_exec} ..." _techo "${tag}" "Executing ${c_pre_exec} ..."
"${c_pre_exec}"; ret="$?" "${c_pre_exec}"; ret="$?"
_techo "Finished ${c_pre_exec} (return code ${ret})." _techo "${tag}" "Finished ${c_pre_exec} (return code ${ret})."
[ "${ret}" -eq 0 ] || _exit_err "${c_pre_exec} failed. Skipping." [ "${ret}" -eq 0 ] || _exit_err "${tag}" "${c_pre_exec} failed. Skipping."
fi fi
# #
@ -583,7 +584,7 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
c_interval="$(cat "${CDEFAULTS}/intervals/${INTERVAL}" 2>/dev/null)" c_interval="$(cat "${CDEFAULTS}/intervals/${INTERVAL}" 2>/dev/null)"
if [ -z "${c_interval}" ]; then if [ -z "${c_interval}" ]; then
_exit_err "No definition for interval \"${INTERVAL}\" found. Skipping." _exit_err "${tag}" "No definition for interval \"${INTERVAL}\" found. Skipping."
fi fi
fi fi
@ -612,11 +613,11 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
# Destination is a path # Destination is a path
# #
if [ ! -f "${c_dest}" ]; then if [ ! -f "${c_dest}" ]; then
_exit_err "Destination ${c_dest} is not a file. Skipping." _exit_err "${tag}" "Destination ${c_dest} is not a file. Skipping."
else else
ddir="$(cat "${c_dest}")"; ret="$?" ddir="$(cat "${c_dest}")"; ret="$?"
if [ "${ret}" -ne 0 ]; then if [ "${ret}" -ne 0 ]; then
_exit_err "Destination ${c_dest} is not readable. Skipping." _exit_err "${tag}" "Destination ${c_dest} is not readable. Skipping."
fi fi
fi fi
@ -681,7 +682,7 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
if [ ! -f "${c_quiet_if_down}" ]; then if [ ! -f "${c_quiet_if_down}" ]; then
cat "${TMP}" cat "${TMP}"
fi fi
_exit_err "Source ${source} is not readable. Skipping." _exit_err "${tag}" "Source ${source} is not readable. Skipping."
fi fi
# #
@ -692,7 +693,7 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
# #
# Check: destination exists? # Check: destination exists?
# #
cd "${ddir}" || _exit_err "Cannot change to ${ddir}. Skipping." cd "${ddir}" || _exit_err "${tag}" "Cannot change to ${ddir}. Skipping."
# #
# Check incomplete backups (needs echo to remove newlines) # Check incomplete backups (needs echo to remove newlines)
@ -700,7 +701,7 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
ls -1 | grep "${CMARKER}\$" > "${TMP}"; ret=$? ls -1 | grep "${CMARKER}\$" > "${TMP}"; ret=$?
if [ "$ret" -eq 0 ]; then if [ "$ret" -eq 0 ]; then
_techo "Incomplete backups: $(echo $(cat "${TMP}"))" _techo "${tag}" "Incomplete backups: $(echo $(cat "${TMP}"))"
if [ -f "${c_delete_incomplete}" ]; then if [ -f "${c_delete_incomplete}" ]; then
delete_from_file "${TMP}" "${CMARKER}" delete_from_file "${TMP}" "${CMARKER}"
fi fi
@ -711,14 +712,14 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
# #
count="$(ls -1 | grep -c "^${INTERVAL}\\.")" count="$(ls -1 | grep -c "^${INTERVAL}\\.")"
_techo "Existing backups: ${count} Total keeping backups: ${c_interval}" _techo "${tag}" "Existing backups: ${count} Total keeping backups: ${c_interval}"
if [ "${count}" -ge "${c_interval}" ]; then if [ "${count}" -ge "${c_interval}" ]; then
remove="$((${count} - ${c_interval} + 1))" remove="$((${count} - ${c_interval} + 1))"
_techo "Removing ${remove} backup(s)..." _techo "${tag}" "Removing ${remove} backup(s)..."
ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \ ls -${TSORT}1r | grep "^${INTERVAL}\\." | head -n "${remove}" > "${TMP}" || \
_exit_err "Listing old backups failed" _exit_err "${tag}" "Listing old backups failed"
delete_from_file "${TMP}" delete_from_file "${TMP}"
fi fi
@ -727,14 +728,14 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
# Check for backup directory to clone from: Always clone from the latest one! # Check for backup directory to clone from: Always clone from the latest one!
# #
last_dir="$(ls -${TSORT}p1 | grep '/$' | head -n 1)" || \ last_dir="$(ls -${TSORT}p1 | grep '/$' | head -n 1)" || \
_exit_err "Failed to list contents of ${ddir}." _exit_err "${tag}" "Failed to list contents of ${ddir}."
# #
# Clone from old backup, if existing # Clone from old backup, if existing
# #
if [ "${last_dir}" ]; then if [ "${last_dir}" ]; then
set -- "$@" "--link-dest=${ddir}/${last_dir}" set -- "$@" "--link-dest=${ddir}/${last_dir}"
_techo "Hard linking from ${last_dir}" _techo "${tag}" "Hard linking from ${last_dir}"
fi fi
# #
@ -747,14 +748,14 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
# Mark backup running and go back to original directory # Mark backup running and go back to original directory
# #
touch "${destination_dir}${CMARKER}" touch "${destination_dir}${CMARKER}"
cd "${__abs_mydir}" || _exit_err "Cannot go back to ${__abs_mydir}." cd "${__abs_mydir}" || _exit_err "${tag}" "Cannot go back to ${__abs_mydir}."
# #
# the rsync part # the rsync part
# #
_techo "Transferring files..." _techo "${tag}" "Transferring files..."
rsync "$@" "${source}" "${destination_dir}"; ret=$? rsync "$@" "${source}" "${destination_dir}"; ret=$?
_techo "Finished backup (rsync return code: $ret)." _techo "${tag}" "Finished backup (rsync return code: $ret)."
# #
# Set modification time (mtime) to current time, if sorting by mtime is enabled # Set modification time (mtime) to current time, if sorting by mtime is enabled
@ -778,24 +779,24 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
# #
if [ -z "$fail" ]; then if [ -z "$fail" ]; then
rm "${destination_dir}${CMARKER}" || \ rm "${destination_dir}${CMARKER}" || \
_exit_err "Removing ${destination_dir}${CMARKER} failed." _exit_err "${tag}" "Removing ${destination_dir}${CMARKER} failed."
if [ "${ret}" -ne 0 ]; then if [ "${ret}" -ne 0 ]; then
_techo "Warning: rsync exited non-zero, the backup may be broken (see rsync errors)." _techo "${tag}" "Warning: rsync exited non-zero, the backup may be broken (see rsync errors)."
fi fi
else else
_techo "Warning: rsync failed with return code $ret." _techo "${tag}" "Warning: rsync failed with return code $ret."
fi fi
# #
# post_exec # post_exec
# #
if [ -x "${c_post_exec}" ]; then if [ -x "${c_post_exec}" ]; then
_techo "Executing ${c_post_exec} ..." _techo "${tag}" "Executing ${c_post_exec} ..."
"${c_post_exec}"; ret=$? "${c_post_exec}"; ret=$?
_techo "Finished ${c_post_exec}." _techo "${tag}" "Finished ${c_post_exec}."
if [ "${ret}" -ne 0 ]; then if [ "${ret}" -ne 0 ]; then
_exit_err "${c_post_exec} failed." _exit_err "${tag}" "${c_post_exec} failed."
fi fi
fi fi
@ -808,7 +809,7 @@ while [ "${source_no}" -lt "${no_sources}" ]; do
minutes="$(((${full_seconds} % 3600) / 60))" minutes="$(((${full_seconds} % 3600) / 60))"
seconds="$((${full_seconds} % 60))" seconds="$((${full_seconds} % 60))"
_techo "Backup lasted: ${hours}:${minutes}:${seconds} (h:m:s)" _techo "${tag}" "Backup lasted: ${hours}:${minutes}:${seconds} (h:m:s)"
unlock "${name}" unlock "${name}"
) | add_name ) | add_name

View file

@ -1 +1,2 @@
* Add Windows(Cygwin) as supported OS * Add Windows(Cygwin) as supported OS
* Add source name tag in log line