Skip to content

Commit 2e6abc2

Browse files
authored
Merge pull request #37 from buildplan/fix_ntfy
fix ntfy alerts
2 parents fb1c36e + 4020607 commit 2e6abc2

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ To run the backup automatically, edit the root crontab.
184184
185185
```ini
186186
# =================================================================
187-
# Configuration for rsync Backup Script v0.31
187+
# Configuration for rsync Backup Script v0.32
188188
# =================================================================
189189
# !! IMPORTANT !! Set file permissions to 600 (chmod 600 backup.conf)
190190
@@ -311,7 +311,7 @@ END_EXCLUDES
311311
312312
```bash
313313
#!/bin/bash
314-
# ===================== v0.31 - 2025.08.13 ========================
314+
# ===================== v0.32 - 2025.08.13 ========================
315315
#
316316
# =================================================================
317317
# SCRIPT INITIALIZATION & SETUP
@@ -570,7 +570,7 @@ run_preflight_checks() {
570570
# Quick preflight connectivity "ping": short 10s timeout for fail-fast behaviour
571571
if ! ssh "${SSH_OPTS_ARRAY[@]}" -o BatchMode=yes -o ConnectTimeout=10 "$BOX_ADDR" 'exit' 2>/dev/null; then
572572
local err_msg="Unable to SSH into $BOX_ADDR. Check keys and connectivity."
573-
if [[ "$test_mode" == "true" ]]; then echo "$err_msg"; else send_notification "SSH FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "$err_msg"; fi; exit 6
573+
if [[ "$test_mode" == "true" ]]; then echo "$err_msg"; else send_notification "SSH FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "$err_msg"; fi; exit 6
574574
fi
575575
if [[ "$test_mode" == "true" ]]; then printf "${C_GREEN}✅ SSH connectivity OK.${C_RESET}\n"; fi
576576
if [[ "${RECYCLE_BIN_ENABLED:-false}" == "true" ]]; then
@@ -765,11 +765,11 @@ run_restore_mode() {
765765
if rsync "${rsync_restore_opts[@]}" "${extra_rsync_opts[@]}" "$full_remote_source" "$final_dest"; then
766766
log_message "Restore completed successfully."
767767
printf "${C_GREEN}✅ Restore of %s to '%s' completed successfully.${C_RESET}\n" "$item_for_display" "$final_dest"
768-
send_notification "Restore SUCCESS: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "Successfully restored ${item_for_display} to ${final_dest}"
768+
send_notification "Restore SUCCESS: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "Successfully restored ${item_for_display} to ${final_dest}"
769769
else
770770
log_message "Restore FAILED with rsync exit code $?."
771771
printf "${C_RED}❌ Restore FAILED. Check the rsync output and log for details.${C_RESET}\n"
772-
send_notification "Restore FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "Restore of ${item_for_display} to ${final_dest} failed."
772+
send_notification "Restore FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "Restore of ${item_for_display} to ${final_dest} failed."
773773
return 1
774774
fi
775775
}
@@ -819,7 +819,7 @@ run_recycle_bin_cleanup() {
819819
fi
820820
}
821821
trap cleanup EXIT
822-
trap 'send_notification "Backup Crashed: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "Backup script terminated unexpectedly. Check log: ${LOG_FILE:-/dev/null}"' ERR
822+
trap 'send_notification "Backup Crashed: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "Backup script terminated unexpectedly. Check log: ${LOG_FILE:-/dev/null}"' ERR
823823

824824
REQUIRED_CMDS=(rsync ssh curl flock hostname date stat mv touch awk numfmt grep printf nice ionice sed mktemp basename read)
825825

@@ -874,13 +874,13 @@ if [[ "${1:-}" ]]; then
874874
if [ -z "$CLEAN_DISCREPANCIES" ]; then
875875
echo "✅ Checksum validation passed. No discrepancies found."
876876
log_message "Checksum validation passed. No discrepancies found."
877-
send_notification "Backup Integrity OK: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "Checksum validation passed."
877+
send_notification "Backup Integrity OK: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "Checksum validation passed."
878878
else
879879
log_message "Backup integrity check FAILED. Found discrepancies."
880880
ISSUE_LIST=$(echo "$CLEAN_DISCREPANCIES" | head -n 10)
881881
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))
882882
printf "❌ %s\n" "$FAILURE_MSG"
883-
send_notification "Backup Integrity FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "${FAILURE_MSG}"
883+
send_notification "Backup Integrity FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "${FAILURE_MSG}"
884884
fi
885885
fi
886886
exit 0 ;;
@@ -963,12 +963,12 @@ fi
963963
if [[ ${#failed_dirs[@]} -eq 0 ]]; then
964964
log_message "SUCCESS: All backups completed."
965965
if [[ $overall_exit_code -eq 24 ]]; then
966-
send_notification "⚠️ Backup Warning: ${HOSTNAME}" "warning" "${NTFY_PRIORITY_WARNING}" "warning" "One or more directories completed with warnings.\n\n$FINAL_MESSAGE"
966+
send_notification "Backup Warning: ${HOSTNAME}" "warning" "${NTFY_PRIORITY_WARNING}" "warning" "One or more directories completed with warnings.\n\n$FINAL_MESSAGE"
967967
else
968-
send_notification "Backup SUCCESS: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "$FINAL_MESSAGE"
968+
send_notification "Backup SUCCESS: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "$FINAL_MESSAGE"
969969
fi
970970
else
971-
log_message "FAILURE: One or more backups failed."; send_notification "Backup FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "$FINAL_MESSAGE"
971+
log_message "FAILURE: One or more backups failed."; send_notification "Backup FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "$FINAL_MESSAGE"
972972
fi
973973

974974
echo "======================= Run Finished =======================" >> "$LOG_FILE"

backup.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# =================================================================
2-
# Configuration for rsync Backup Script v0.31
2+
# Configuration for rsync Backup Script v0.32
33
# =================================================================
44
# !! IMPORTANT !! Set file permissions to 600 (chmod 600 backup.conf)
55

backup_script.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# ===================== v0.31 - 2025.08.13 ========================
2+
# ===================== v0.32 - 2025.08.13 ========================
33
#
44
# Example backup.conf:
55
# BACKUP_DIRS="/home/user/test/./ /var/www/./"
@@ -289,7 +289,7 @@ run_preflight_checks() {
289289
# Quick preflight connectivity "ping": short 10s timeout for fail-fast behaviour
290290
if ! ssh "${SSH_OPTS_ARRAY[@]}" -o BatchMode=yes -o ConnectTimeout=10 "$BOX_ADDR" 'exit' 2>/dev/null; then
291291
local err_msg="Unable to SSH into $BOX_ADDR. Check keys and connectivity."
292-
if [[ "$test_mode" == "true" ]]; then echo "$err_msg"; else send_notification "SSH FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "$err_msg"; fi; exit 6
292+
if [[ "$test_mode" == "true" ]]; then echo "$err_msg"; else send_notification "SSH FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "$err_msg"; fi; exit 6
293293
fi
294294
if [[ "$test_mode" == "true" ]]; then printf "${C_GREEN}✅ SSH connectivity OK.${C_RESET}\n"; fi
295295
if [[ "${RECYCLE_BIN_ENABLED:-false}" == "true" ]]; then
@@ -484,11 +484,11 @@ run_restore_mode() {
484484
if rsync "${rsync_restore_opts[@]}" "${extra_rsync_opts[@]}" "$full_remote_source" "$final_dest"; then
485485
log_message "Restore completed successfully."
486486
printf "${C_GREEN}✅ Restore of %s to '%s' completed successfully.${C_RESET}\n" "$item_for_display" "$final_dest"
487-
send_notification "Restore SUCCESS: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "Successfully restored ${item_for_display} to ${final_dest}"
487+
send_notification "Restore SUCCESS: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "Successfully restored ${item_for_display} to ${final_dest}"
488488
else
489489
log_message "Restore FAILED with rsync exit code $?."
490490
printf "${C_RED}❌ Restore FAILED. Check the rsync output and log for details.${C_RESET}\n"
491-
send_notification "Restore FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "Restore of ${item_for_display} to ${final_dest} failed."
491+
send_notification "Restore FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "Restore of ${item_for_display} to ${final_dest} failed."
492492
return 1
493493
fi
494494
}
@@ -538,7 +538,7 @@ run_recycle_bin_cleanup() {
538538
fi
539539
}
540540
trap cleanup EXIT
541-
trap 'send_notification "Backup Crashed: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "Backup script terminated unexpectedly. Check log: ${LOG_FILE:-/dev/null}"' ERR
541+
trap 'send_notification "Backup Crashed: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "Backup script terminated unexpectedly. Check log: ${LOG_FILE:-/dev/null}"' ERR
542542

543543
REQUIRED_CMDS=(rsync ssh curl flock hostname date stat mv touch awk numfmt grep printf nice ionice sed mktemp basename read)
544544

@@ -593,13 +593,13 @@ if [[ "${1:-}" ]]; then
593593
if [ -z "$CLEAN_DISCREPANCIES" ]; then
594594
echo "✅ Checksum validation passed. No discrepancies found."
595595
log_message "Checksum validation passed. No discrepancies found."
596-
send_notification "Backup Integrity OK: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "Checksum validation passed."
596+
send_notification "Backup Integrity OK: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "Checksum validation passed."
597597
else
598598
log_message "Backup integrity check FAILED. Found discrepancies."
599599
ISSUE_LIST=$(echo "$CLEAN_DISCREPANCIES" | head -n 10)
600600
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))
601601
printf "❌ %s\n" "$FAILURE_MSG"
602-
send_notification "Backup Integrity FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "${FAILURE_MSG}"
602+
send_notification "Backup Integrity FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "${FAILURE_MSG}"
603603
fi
604604
fi
605605
exit 0 ;;
@@ -682,12 +682,12 @@ fi
682682
if [[ ${#failed_dirs[@]} -eq 0 ]]; then
683683
log_message "SUCCESS: All backups completed."
684684
if [[ $overall_exit_code -eq 24 ]]; then
685-
send_notification "⚠️ Backup Warning: ${HOSTNAME}" "warning" "${NTFY_PRIORITY_WARNING}" "warning" "One or more directories completed with warnings.\n\n$FINAL_MESSAGE"
685+
send_notification "Backup Warning: ${HOSTNAME}" "warning" "${NTFY_PRIORITY_WARNING}" "warning" "One or more directories completed with warnings.\n\n$FINAL_MESSAGE"
686686
else
687-
send_notification "Backup SUCCESS: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "$FINAL_MESSAGE"
687+
send_notification "Backup SUCCESS: ${HOSTNAME}" "white_check_mark" "${NTFY_PRIORITY_SUCCESS}" "success" "$FINAL_MESSAGE"
688688
fi
689689
else
690-
log_message "FAILURE: One or more backups failed."; send_notification "Backup FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "$FINAL_MESSAGE"
690+
log_message "FAILURE: One or more backups failed."; send_notification "Backup FAILED: ${HOSTNAME}" "x" "${NTFY_PRIORITY_FAILURE}" "failure" "$FINAL_MESSAGE"
691691
fi
692692

693693
echo "======================= Run Finished =======================" >> "$LOG_FILE"

backup_script.sh.sha256

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c86ad2b090ee73e7489315bad8650022943b1b5df57d64e84252e306b6d91750 backup_script.sh
1+
6f989d6cc03d6f507ee48ba93b6b44645ee6e3aaf1da0ee73577056f6c13ea84 backup_script.sh

0 commit comments

Comments
 (0)