fixes and improves
All checks were successful
Check scripts syntax / check-scripts-syntax (push) Successful in 40s

This commit is contained in:
2026-06-21 12:09:14 -03:00
parent 36a0444344
commit 7ac6d16180
3 changed files with 12 additions and 22 deletions

View File

@@ -42,7 +42,7 @@ Optional:
- `NOTIFY_FAILURE_URL` (default: empty, disabled) - `NOTIFY_FAILURE_URL` (default: empty, disabled)
- `NOTIFY_TITLE` (default: `Kubernetes`) - `NOTIFY_TITLE` (default: `Kubernetes`)
- `NOTIFY_ASSET` (default: `kube config`) - `NOTIFY_ASSET` (default: `kube config`)
- `CLEANUP_DELETE_COUNT` (default: `5`) - `CLEANUP_KEEP_COUNT` (default: `4`)
Notification payload (success and failure): Notification payload (success and failure):
@@ -69,7 +69,7 @@ Notification payload (success and failure):
- Restore warnings/timeouts: logged and counted, script does not fail solely because of restore warnings. - Restore warnings/timeouts: logged and counted, script does not fail solely because of restore warnings.
- If `NOTIFY_SUCCESS_URL` is set, success notification is sent at the end of a successful run. - If `NOTIFY_SUCCESS_URL` is set, success notification is sent at the end of a successful run.
- If `NOTIFY_FAILURE_URL` is set, failure notification is sent when backup failures are detected. - If `NOTIFY_FAILURE_URL` is set, failure notification is sent when backup failures are detected.
- On successful runs, cleanup removes the last `CLEANUP_DELETE_COUNT` archives by date ordering (oldest side), without deleting the final remaining archive. - On successful runs, cleanup removes the last `CLEANUP_KEEP_COUNT` archives by date ordering (oldest side), without deleting the final remaining archive.
- Final summary always logs: - Final summary always logs:
- `processed` - `processed`
- `mapped` - `mapped`

View File

@@ -33,7 +33,7 @@ NOTIFY_SUCCESS_URL="${NOTIFY_SUCCESS_URL:-}"
NOTIFY_FAILURE_URL="${NOTIFY_FAILURE_URL:-}" NOTIFY_FAILURE_URL="${NOTIFY_FAILURE_URL:-}"
NOTIFY_TITLE="${NOTIFY_TITLE:-Kubernetes}" NOTIFY_TITLE="${NOTIFY_TITLE:-Kubernetes}"
NOTIFY_ASSET="${NOTIFY_ASSET:-kube config}" NOTIFY_ASSET="${NOTIFY_ASSET:-kube config}"
CLEANUP_DELETE_COUNT="${CLEANUP_DELETE_COUNT:-5}" CLEANUP_KEEP_COUNT="${CLEANUP_KEEP_COUNT:-4}"
KUBECTL_ARGS=() KUBECTL_ARGS=()
if [[ -n "$KUBE_CONTEXT" ]]; then if [[ -n "$KUBE_CONTEXT" ]]; then
@@ -83,8 +83,8 @@ validate_inputs() {
die "NFS_SOURCE_PATH does not exist or is not a directory: ${NFS_SOURCE_PATH}" die "NFS_SOURCE_PATH does not exist or is not a directory: ${NFS_SOURCE_PATH}"
fi fi
if [[ ! "$CLEANUP_DELETE_COUNT" =~ ^[0-9]+$ ]]; then if [[ ! "$CLEANUP_KEEP_COUNT" =~ ^[0-9]+$ ]]; then
die "CLEANUP_DELETE_COUNT must be an integer >= 0" die "CLEANUP_KEEP_COUNT must be an integer >= 0"
fi fi
if [[ -z "$BACKUP_PASSWORD" ]]; then if [[ -z "$BACKUP_PASSWORD" ]]; then
@@ -379,8 +379,8 @@ backup_folder() {
} }
cleanup_archives() { cleanup_archives() {
if (( CLEANUP_DELETE_COUNT == 0 )); then if (( CLEANUP_KEEP_COUNT == 0 )); then
log_info "Cleanup disabled (CLEANUP_DELETE_COUNT=0)" log_info "Cleanup disabled (CLEANUP_KEEP_COUNT=0)"
return 0 return 0
fi fi
@@ -398,24 +398,14 @@ cleanup_archives() {
mapfile -t sorted_archives < <(ls -1t -- "${archive_candidates[@]}") mapfile -t sorted_archives < <(ls -1t -- "${archive_candidates[@]}")
local total_sorted="${#sorted_archives[@]}" local total_sorted="${#sorted_archives[@]}"
if (( total_sorted <= 1 )); then if (( total_sorted <= CLEANUP_KEEP_COUNT )); then
log_info "Cleanup skipped: only one archive present" log_info "Cleanup skipped: ${total_sorted} archive(s) present, keeping ${CLEANUP_KEEP_COUNT}"
return 0 return 0
fi fi
local delete_count="$CLEANUP_DELETE_COUNT" local keep_count="$CLEANUP_KEEP_COUNT"
local max_deletable=$((total_sorted - 1))
if (( delete_count > max_deletable )); then
delete_count="$max_deletable"
fi
if (( delete_count == 0 )); then
return 0
fi
local start_index=$((total_sorted - delete_count))
local i local i
for ((i = start_index; i < total_sorted; i++)); do for ((i = keep_count; i < total_sorted; i++)); do
local archive_path="${sorted_archives[$i]}" local archive_path="${sorted_archives[$i]}"
rm -f -- "$archive_path" rm -f -- "$archive_path"
log_info "Cleanup deleted archive: ${archive_path}" log_info "Cleanup deleted archive: ${archive_path}"

View File

@@ -19,4 +19,4 @@ NOTIFY_SUCCESS_URL=
NOTIFY_FAILURE_URL= NOTIFY_FAILURE_URL=
NOTIFY_TITLE=Kubernetes NOTIFY_TITLE=Kubernetes
NOTIFY_ASSET=kube config NOTIFY_ASSET=kube config
CLEANUP_DELETE_COUNT=5 CLEANUP_KEEP_COUNT=5