From 62f1e0a9c279d1df3ffc9426b5751b36a5b81724 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Thu, 12 May 2022 08:41:18 -0600 Subject: [PATCH] fix out of order deletion --- heavy_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heavy_script.sh b/heavy_script.sh index 827a2f50..082f5a44 100644 --- a/heavy_script.sh +++ b/heavy_script.sh @@ -86,7 +86,7 @@ mapfile -t list_backups < <(cli -c 'app kubernetes list_backups' | grep "HeavySc if [[ ${#list_backups[@]} -gt "number_of_backups" ]]; then echo -e "\nDeleting the oldest backup(s) for exceeding limit:" overflow=$(expr ${#list_backups[@]} - $number_of_backups) - mapfile -t list_overflow < <(cli -c 'app kubernetes list_backups' | grep "HeavyScript_" | sort -t '_' -Vr -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r" | tail -n "$overflow") + mapfile -t list_overflow < <(cli -c 'app kubernetes list_backups' | grep "HeavyScript_" | sort -t '_' -Vr -k2,7 | awk -F '|' '{print $2}'| tr -d " \t\r" | tail -n "$overflow" | sort -t '_' -V -k2,7) for i in "${list_overflow[@]}" do cli -c 'app kubernetes delete_backup backup_name=''"'"$i"'"' &> /dev/null || echo "Failed to delete $i"