more fixes
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 4s
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 4s
This commit is contained in:
@@ -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 <<EOF
|
||||
{
|
||||
"caller": "$(json_escape "$NOTIFY_CALLER")",
|
||||
"message": "$(json_escape "$message")",
|
||||
"critical": true,
|
||||
"extra": [
|
||||
{
|
||||
"name": "Backup Size (MB)",
|
||||
"value": "${size_mb}"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
if ! curl -fsS -X POST "$url" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$payload" >/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
|
||||
|
||||
Reference in New Issue
Block a user