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

@@ -33,7 +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}"
CLEANUP_DELETE_COUNT="${CLEANUP_DELETE_COUNT:-5}"
CLEANUP_KEEP_COUNT="${CLEANUP_KEEP_COUNT:-4}"
KUBECTL_ARGS=()
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}"
fi
if [[ ! "$CLEANUP_DELETE_COUNT" =~ ^[0-9]+$ ]]; then
die "CLEANUP_DELETE_COUNT must be an integer >= 0"
if [[ ! "$CLEANUP_KEEP_COUNT" =~ ^[0-9]+$ ]]; then
die "CLEANUP_KEEP_COUNT must be an integer >= 0"
fi
if [[ -z "$BACKUP_PASSWORD" ]]; then
@@ -379,8 +379,8 @@ backup_folder() {
}
cleanup_archives() {
if (( CLEANUP_DELETE_COUNT == 0 )); then
log_info "Cleanup disabled (CLEANUP_DELETE_COUNT=0)"
if (( CLEANUP_KEEP_COUNT == 0 )); then
log_info "Cleanup disabled (CLEANUP_KEEP_COUNT=0)"
return 0
fi
@@ -398,24 +398,14 @@ cleanup_archives() {
mapfile -t sorted_archives < <(ls -1t -- "${archive_candidates[@]}")
local total_sorted="${#sorted_archives[@]}"
if (( total_sorted <= 1 )); then
log_info "Cleanup skipped: only one archive present"
if (( total_sorted <= CLEANUP_KEEP_COUNT )); then
log_info "Cleanup skipped: ${total_sorted} archive(s) present, keeping ${CLEANUP_KEEP_COUNT}"
return 0
fi
local delete_count="$CLEANUP_DELETE_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 keep_count="$CLEANUP_KEEP_COUNT"
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]}"
rm -f -- "$archive_path"
log_info "Cleanup deleted archive: ${archive_path}"