Skip to content

Commit 4438939

Browse files
authored
Sort backup file list before retention check (Fixes hestiacp#5017) (hestiacp#5018)
1 parent bbcac25 commit 4438939

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

func/backup.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ local_backup() {
1313
rm -f $BACKUP/$user.$backup_new_date.tar
1414

1515
# Checking retention
16-
backup_list=$(ls -lrt $BACKUP/ | awk '{print $9}' | grep "^$user\." | grep ".tar")
16+
backup_list=$(ls -lrt $BACKUP/ | awk '{print $9}' | grep "^$user\." | grep ".tar" | sort)
1717
backups_count=$(echo "$backup_list" | wc -l)
1818
if [ "$BACKUPS" -le "$backups_count" ]; then
1919
backups_rm_number=$((backups_count - BACKUPS + 1))
@@ -126,9 +126,9 @@ ftp_backup() {
126126

127127
# Checking retention (Only include .tar files)
128128
if [ -z $BPATH ]; then
129-
backup_list=$(ftpc "ls" | awk '{print $9}' | grep "^$user\." | grep ".tar")
129+
backup_list=$(ftpc "ls" | awk '{print $9}' | grep "^$user\." | grep ".tar" | sort)
130130
else
131-
backup_list=$(ftpc "cd $BPATH" "ls" | awk '{print $9}' | grep "^$user\." | grep ".tar")
131+
backup_list=$(ftpc "cd $BPATH" "ls" | awk '{print $9}' | grep "^$user\." | grep ".tar" | sort)
132132
fi
133133
backups_count=$(echo "$backup_list" | wc -l)
134134
if [ "$backups_count" -ge "$BACKUPS" ]; then
@@ -401,9 +401,9 @@ sftp_backup() {
401401

402402
# Checking retention (Only include .tar files)
403403
if [ -z $BPATH ]; then
404-
backup_list=$(sftpc "ls -l" | awk '{print $9}' | grep "^$user\." | grep ".tar")
404+
backup_list=$(sftpc "ls -l" | awk '{print $9}' | grep "^$user\." | grep ".tar" | sort)
405405
else
406-
backup_list=$(sftpc "cd $BPATH" "ls -l" | awk '{print $9}' | grep "^$user\." | grep ".tar")
406+
backup_list=$(sftpc "cd $BPATH" "ls -l" | awk '{print $9}' | grep "^$user\." | grep ".tar" | sort)
407407
fi
408408
backups_count=$(echo "$backup_list" | wc -l)
409409
if [ "$backups_count" -ge "$BACKUPS" ]; then
@@ -524,7 +524,7 @@ rclone_backup() {
524524
fi
525525

526526
# Only include *.tar files
527-
backup_list=$(rclone lsf $HOST: | cut -d' ' -f1 | grep "^$user\." | grep ".tar")
527+
backup_list=$(rclone lsf $HOST: | cut -d' ' -f1 | grep "^$user\." | grep ".tar" | sort)
528528
backups_count=$(echo "$backup_list" | wc -l)
529529
backups_rm_number=$((backups_count - BACKUPS))
530530
if [ "$backups_count" -ge "$BACKUPS" ]; then
@@ -540,7 +540,7 @@ rclone_backup() {
540540
fi
541541

542542
# Only include *.tar files
543-
backup_list=$(rclone lsf $HOST:$BPATH | cut -d' ' -f1 | grep "^$user\." | grep ".tar")
543+
backup_list=$(rclone lsf $HOST:$BPATH | cut -d' ' -f1 | grep "^$user\." | grep ".tar" | sort)
544544
backups_count=$(echo "$backup_list" | wc -l)
545545
backups_rm_number=$(($backups_count - $BACKUPS))
546546
if [ "$backups_count" -ge "$BACKUPS" ]; then

0 commit comments

Comments
 (0)