sync.sh: minor logging changes
This commit is contained in:
42
bash/sync.sh
42
bash/sync.sh
@@ -241,9 +241,9 @@ trap 'error_handler $LINENO $?' ERR SIGHUP SIGINT SIGTERM
|
|||||||
exit_handler() {
|
exit_handler() {
|
||||||
# we dont need lock file anymore (another backup could start from now).
|
# we dont need lock file anymore (another backup could start from now).
|
||||||
log "exit_handler LOCKED=$LOCKED"
|
log "exit_handler LOCKED=$LOCKED"
|
||||||
#if [[ "$LOCKED" = y ]]; then
|
if [[ "$LOCKED" = y ]]; then
|
||||||
rm --dir --verbose "${LOCKFILE}"
|
rm --dir --verbose "${LOCKFILE}"
|
||||||
#fi
|
fi
|
||||||
|
|
||||||
if (( ERROR == 0 )); then
|
if (( ERROR == 0 )); then
|
||||||
SUBJECT="Successful $SUBJECT"
|
SUBJECT="Successful $SUBJECT"
|
||||||
@@ -269,8 +269,14 @@ exit_handler() {
|
|||||||
# more handled the final way.
|
# more handled the final way.
|
||||||
{
|
{
|
||||||
# we write these logs here so that they are on top if no DEBUG.
|
# we write these logs here so that they are on top if no DEBUG.
|
||||||
printf "%s: Exit code: %d\n\n" "$CMDNAME" "$ERROR"
|
printf "%s: Exit code: %d " "$CMDNAME" "$ERROR"
|
||||||
printf "Elapsed time: %d seconds (%d:%02d:%02d)\n\n" \
|
if ((ERROR == 0)); then
|
||||||
|
printf "(ok) "
|
||||||
|
else
|
||||||
|
printf "(error) "
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "in %d seconds (%d:%02d:%02d)\n\n" \
|
||||||
$((SECS)) $((SECS/3600)) $((SECS%3600/60)) $((SECS%60))
|
$((SECS)) $((SECS/3600)) $((SECS%3600/60)) $((SECS%60))
|
||||||
|
|
||||||
if [[ -n $FILTERLNK ]]; then
|
if [[ -n $FILTERLNK ]]; then
|
||||||
@@ -304,7 +310,7 @@ exit_handler() {
|
|||||||
printf "\n--%s--\n" "$MIMESTR"
|
printf "\n--%s--\n" "$MIMESTR"
|
||||||
} | mail -a "$MIMEHDR" -s "${SUBJECT}" "${MAILTO}"
|
} | mail -a "$MIMEHDR" -s "${SUBJECT}" "${MAILTO}"
|
||||||
else
|
else
|
||||||
cat
|
grep -vE "^\*+\ Mark$"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,17 +341,12 @@ TODO=()
|
|||||||
[[ $MONTHLY = y && $NMONTHS -gt 0 ]] && TODO+=(monthly "$NMONTHS")
|
[[ $MONTHLY = y && $NMONTHS -gt 0 ]] && TODO+=(monthly "$NMONTHS")
|
||||||
[[ $YEARLY = y && $NYEARS -gt 0 ]] && TODO+=(yearly "$NYEARS")
|
[[ $YEARLY = y && $NYEARS -gt 0 ]] && TODO+=(yearly "$NYEARS")
|
||||||
|
|
||||||
log -l -t "Starting backup."
|
log -l -t "Starting $CMDNAME"
|
||||||
log "Hostname: $(hostname)"
|
log "bash version: ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}.${BASH_VERSINFO[2]}"
|
||||||
log "Operating System: $(uname -sr) on $(uname -m)"
|
|
||||||
log "Bash version: ${BASH_VERSINFO[0]}.${BASH_VERSINFO[1]}.${BASH_VERSINFO[2]}"
|
# check availability of necessary commands
|
||||||
log "Config : ${CONFIG}"
|
|
||||||
log "Src dir: ${SOURCEDIR}"
|
|
||||||
log "Dst dir: ${SERVER}:${DESTDIR}"
|
|
||||||
log "Actions: ${TODO[*]}"
|
|
||||||
# check for available gzip and uuencode
|
|
||||||
declare -a cmdavail=()
|
declare -a cmdavail=()
|
||||||
for cmd in gzip uuencode; do
|
for cmd in gzip uuencode mail rsync; do
|
||||||
log -n "Checking for $cmd... "
|
log -n "Checking for $cmd... "
|
||||||
if type -p "$cmd" > /dev/null; then
|
if type -p "$cmd" > /dev/null; then
|
||||||
log "ok"
|
log "ok"
|
||||||
@@ -355,10 +356,17 @@ for cmd in gzip uuencode; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if (( ${#cmdavail[@]} )); then
|
if (( ${#cmdavail[@]} )); then
|
||||||
log -s "Fatal. Please install the following: ${cmdavail[*]}."
|
log -s "Fatal. Please install the following programs: ${cmdavail[*]}."
|
||||||
error_handler $LINENO 1
|
error_handler $LINENO 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
log "Hostname: $(hostname)"
|
||||||
|
log "Operating System: $(uname -sr) on $(uname -m)"
|
||||||
|
log "Config : ${CONFIG}"
|
||||||
|
log "Src dir: ${SOURCEDIR}"
|
||||||
|
log "Dst dir: ${SERVER}:${DESTDIR}"
|
||||||
|
log "Actions: ${TODO[*]}"
|
||||||
|
|
||||||
log -s "Mark" # to separate email body
|
log -s "Mark" # to separate email body
|
||||||
|
|
||||||
# select handling depending on local or networked target (ssh or not).
|
# select handling depending on local or networked target (ssh or not).
|
||||||
|
Reference in New Issue
Block a user