Skip to content

Commit 4b29554

Browse files
committed
updated the filtering method
1 parent 382fb1f commit 4b29554

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

xbackup/backup.sh

+1-10
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,9 @@ clean_old_backups() {
231231
echo "Removing old backups"
232232

233233
local s3_backup_list
234-
local backup_files=()
235234

236235
s3_backup_list=$(s3cmd --config=/root/.s3cfg ls s3://"${S3_BUCKET}${TARGET_DIR}/" | awk '{print $4}')
237-
238-
while IFS= read -r file; do
239-
if [[ ! "$file" =~ _inc ]]; then
240-
backup_files+=("$file")
241-
fi
242-
done <<< "$s3_backup_list"
243-
244-
mapfile -t backup_files < <(echo "$s3_backup_list" | grep -v '_inc')
245-
mapfile -t sorted_backup_files < <(printf "%s\n" "${backup_files[@]}" | sort -t'/' -k4)
236+
mapfile -t sorted_backup_files < <(echo "$s3_backup_list" | grep -v '_inc' | awk -F'/' '{print $NF, $0}' | sort | awk '{print $2}')
246237

247238
if [[ ${#sorted_backup_files[@]} -gt $ROLLING_WINDOW_HR ]]; then
248239
local cutoff_index=$(( ${#sorted_backup_files[@]} - $ROLLING_WINDOW_HR ))

0 commit comments

Comments
 (0)