Skip to content

Commit 0286ad8

Browse files
authored
Update README.md
1 parent 783c1cc commit 0286ad8

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ END_EXCLUDES
222222

223223
# =================================================================
224224
# SCRIPT INITIALIZATION & SETUP
225-
# v0.11 - 2025.08.09
225+
# v0.12 - 2025.08.10
226226
# =================================================================
227227
set -Euo pipefail
228228
umask 077
@@ -332,9 +332,12 @@ run_integrity_check() {
332332
local rsync_check_opts=(-ainc -c --delete --exclude-from="$EXCLUDE_FILE_TMP" --out-format="%n" -e "ssh ${SSH_OPTS_STR:-}")
333333

334334
for dir in $BACKUP_DIRS; do
335-
local remote_subdir="${REMOTE_TARGET}/$(basename "$dir")/"
335+
local remote_path="${REMOTE_TARGET}${dir#/}"
336+
337+
echo "--- Integrity Check: $dir ---" >&2
338+
336339
# shellcheck disable=SC2086
337-
LC_ALL=C rsync "${rsync_check_opts[@]}" "$dir" "$remote_subdir" 2>> "${LOG_FILE:-/dev/null}"
340+
LC_ALL=C rsync "${rsync_check_opts[@]}" "$dir" "$remote_path" 2>> "${LOG_FILE:-/dev/null}"
338341
done
339342
}
340343

@@ -355,7 +358,6 @@ format_backup_stats() {
355358
local files_created=$(parse_stat "$rsync_output" 'Number_of_created_files:' '{s+=$2} END {print s}')
356359
local files_deleted=$(parse_stat "$rsync_output" 'Number_of_deleted_files:' '{s+=$2} END {print s}')
357360

358-
# Fallback for older rsync versions
359361
if [[ -z "$bytes_transferred" && -z "$files_created" && -z "$files_deleted" ]]; then
360362
bytes_transferred=$(parse_stat "$rsync_output" 'Total transferred file size:' '{gsub(/,/, ""); s+=$5} END {print s}')
361363
files_created=$(parse_stat "$rsync_output" 'Number of created files:' '{s+=$5} END {print s}')
@@ -422,10 +424,10 @@ if [[ "${1:-}" ]]; then
422424
echo "--- DRY RUN MODE ACTIVATED ---"
423425
DRY_RUN_FAILED=false
424426
for dir in $BACKUP_DIRS; do
425-
remote_subdir="${REMOTE_TARGET}/$(basename "$dir")/"
426-
echo "--- Checking dry run for: $dir -> $remote_subdir"
427+
remote_path="${REMOTE_TARGET}${dir#/}"
428+
echo "--- Checking dry run for: $dir -> $remote_path"
427429
# shellcheck disable=SC2086
428-
if ! rsync "${RSYNC_BASE_OPTS[@]}" --dry-run --info=progress2 "$dir" "$remote_subdir"; then
430+
if ! rsync "${RSYNC_BASE_OPTS[@]}" --dry-run --info=progress2 "$dir" "$remote_path"; then
429431
DRY_RUN_FAILED=true
430432
fi
431433
done
@@ -440,23 +442,28 @@ if [[ "${1:-}" ]]; then
440442
--checksum | --summary)
441443
echo "--- INTEGRITY CHECK MODE ACTIVATED ---"
442444
echo "Calculating differences..."
445+
START_TIME_INTEGRITY=$(date +%s)
443446
FILE_DISCREPANCIES=$(run_integrity_check)
447+
END_TIME_INTEGRITY=$(date +%s)
448+
DURATION_INTEGRITY=$((END_TIME_INTEGRITY - START_TIME_INTEGRITY))
449+
450+
CLEAN_DISCREPANCIES=$(echo "$FILE_DISCREPANCIES" | grep -v '^\*')
444451

445452
if [[ "$1" == "--summary" ]]; then
446-
MISMATCH_COUNT=$(echo "$FILE_DISCREPANCIES" | wc -l)
453+
MISMATCH_COUNT=$(echo "$CLEAN_DISCREPANCIES" | wc -l)
447454
printf "🚨 Total files with checksum mismatches: %d\n" "$MISMATCH_COUNT"
448455
log_message "Summary mode check found $MISMATCH_COUNT mismatched files."
449456
send_notification "📊 Backup Summary: ${HOSTNAME}" "bar_chart" "${NTFY_PRIORITY_SUCCESS}" "success" "Mismatched files found: $MISMATCH_COUNT"
450457
else # --checksum
451-
if [ -z "$FILE_DISCREPANCIES" ]; then
458+
if [ -z "$CLEAN_DISCREPANCIES" ]; then
452459
echo "✅ Checksum validation passed. No discrepancies found."
453460
log_message "Checksum validation passed. No discrepancies found."
454461
send_notification "✅ Backup Integrity OK: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "Checksum validation passed. No discrepancies found."
455462
else
456463
log_message "Backup integrity check FAILED. Found discrepancies."
457-
ISSUE_LIST=$(echo "${FILE_DISCREPANCIES}" | head -n 10)
458-
printf "Backup integrity check FAILED. First 10 differing files:\n%s\n" "${ISSUE_LIST}"
459-
printf -v FAILURE_MSG "Backup integrity check FAILED.\n\nFirst 10 differing files:\n%s\n\nCheck log for full details." "${ISSUE_LIST}"
464+
ISSUE_LIST=$(echo "$CLEAN_DISCREPANCIES" | head -n 10)
465+
printf -v FAILURE_MSG "Backup integrity check FAILED.\n\nFirst 10 differing files:\n%s\n\nCheck duration: %dm %ds" "${ISSUE_LIST}" $((DURATION_INTEGRITY / 60)) $((DURATION_INTEGRITY % 60))
466+
printf "%s\n" "$FAILURE_MSG"
460467
send_notification "❌ Backup Integrity FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "${FAILURE_MSG}"
461468
fi
462469
fi
@@ -486,7 +493,7 @@ full_rsync_output=""
486493
for dir in $BACKUP_DIRS; do
487494
log_message "Backing up directory: $dir"
488495

489-
remote_subdir="${REMOTE_TARGET}/$(basename "$dir")/"
496+
remote_path="${REMOTE_TARGET}${dir#/}"
490497

491498
RSYNC_LOG_TMP=$(mktemp)
492499
RSYNC_EXIT_CODE=0
@@ -495,12 +502,12 @@ for dir in $BACKUP_DIRS; do
495502
if [[ "$VERBOSE_MODE" == "true" ]]; then
496503
RSYNC_OPTS+=(--info=stats2,progress2)
497504
# shellcheck disable=SC2086
498-
nice -n 19 ionice -c 3 rsync "${RSYNC_OPTS[@]}" "$dir" "$remote_subdir" 2>&1 | tee "$RSYNC_LOG_TMP"
505+
nice -n 19 ionice -c 3 rsync "${RSYNC_OPTS[@]}" "$dir" "$remote_path" 2>&1 | tee "$RSYNC_LOG_TMP"
499506
RSYNC_EXIT_CODE=${PIPESTATUS[0]}
500507
else
501508
RSYNC_OPTS+=(--info=stats2)
502509
# shellcheck disable=SC2086
503-
nice -n 19 ionice -c 3 rsync "${RSYNC_OPTS[@]}" "$dir" "$remote_subdir" > "$RSYNC_LOG_TMP" 2>&1 || RSYNC_EXIT_CODE=$?
510+
nice -n 19 ionice -c 3 rsync "${RSYNC_OPTS[@]}" "$dir" "$remote_path" > "$RSYNC_LOG_TMP" 2>&1 || RSYNC_EXIT_CODE=$?
504511
fi
505512

506513
cat "$RSYNC_LOG_TMP" >> "$LOG_FILE"

0 commit comments

Comments
 (0)