From 2f2ad759c14f3a269b565980a51bf77f3f3449ea Mon Sep 17 00:00:00 2001 From: Jose Henrique Date: Sun, 21 Jun 2026 12:50:29 -0300 Subject: [PATCH] more fixes --- k8s/automated-nfs-backup.sh | 50 ++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/k8s/automated-nfs-backup.sh b/k8s/automated-nfs-backup.sh index 596cfcf..4ddd6d0 100644 --- a/k8s/automated-nfs-backup.sh +++ b/k8s/automated-nfs-backup.sh @@ -33,6 +33,7 @@ NOTIFY_SUCCESS_URL="${NOTIFY_SUCCESS_URL:-}" NOTIFY_FAILURE_URL="${NOTIFY_FAILURE_URL:-}" NOTIFY_TITLE="${NOTIFY_TITLE:-Kubernetes}" NOTIFY_ASSET="${NOTIFY_ASSET:-kube config}" +NOTIFY_CALLER="${NOTIFY_CALLER:-Kubernetes config backup}" CLEANUP_KEEP_COUNT="${CLEANUP_KEEP_COUNT:-4}" KUBECTL_ARGS=() @@ -359,6 +360,38 @@ EOF return 0 } +send_backup_failure_notification() { + local url="${1:-}" + local message="${2:-}" + local size_mb="${3:-0}" + + [[ -z "$url" ]] && return 0 + + local payload + payload=$(cat </dev/null; then + log_warn "Failed to send backup failure notification to ${url}" + return 1 + fi + return 0 +} + backup_folder() { local folder_path="${1:?folder path required}" local archive_path="${2:?archive path required}" @@ -375,7 +408,17 @@ backup_folder() { cmd+=("-p${BACKUP_PASSWORD}" "-mhe=${SEVENZ_HEADER_ENCRYPT}") fi - "${cmd[@]}" >/dev/null + local cmd_output rc filtered_output + cmd_output="$("${cmd[@]}" 2>&1 >/dev/null)" + rc=$? + filtered_output="$(printf '%s\n' "$cmd_output" | grep -v -F 'WARNING: errno=2 : No such file or directory' || true)" + if [[ -n "$filtered_output" ]]; then + log_warn "7z output for '${folder_path}': ${filtered_output}" + fi + if (( rc == 0 || (rc == 1 && -z "$filtered_output") )); then + return 0 + fi + return 1 } cleanup_archives() { @@ -502,10 +545,9 @@ main() { size_mb="$(backup_size_mb "$total_backup_size_bytes")" if (( backup_failures > 0 )); then - send_backup_notification \ + send_backup_failure_notification \ "$NOTIFY_FAILURE_URL" \ - "${NOTIFY_TITLE} - FAILED" \ - "${NOTIFY_ASSET}" \ + "Error while backing up NFS folders" \ "$size_mb" || true die "One or more folder backups failed" 1 fi