Skip to content

Commit 308e4ff

Browse files
authored
hestiacp#3385 Only count *.tar files in rotate routine (hestiacp#3393)
* Improve log message to what endpoint is used * Only check .tar files * Use $HOST:$BPATH instead
1 parent 5d1dfd1 commit 308e4ff

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

func/backup.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ ftp_backup() {
124124
return "$E_FTP"
125125
fi
126126

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

402-
# Checking retention
402+
# Checking retention (Only include .tar files)
403403
if [ -z $BPATH ]; then
404-
backup_list=$(sftpc "ls -l" | awk '{print $9}' | grep "^$user\.")
404+
backup_list=$(sftpc "ls -l" | awk '{print $9}' | grep "^$user\." | grep ".tar")
405405
else
406-
backup_list=$(sftpc "cd $BPATH" "ls -l" | awk '{print $9}' | grep "^$user\.")
406+
backup_list=$(sftpc "cd $BPATH" "ls -l" | awk '{print $9}' | grep "^$user\." | grep ".tar")
407407
fi
408408
backups_count=$(echo "$backup_list" | wc -l)
409409
if [ "$backups_count" -ge "$BACKUPS" ]; then
@@ -510,20 +510,21 @@ b2_delete() {
510510
rclone_backup() {
511511
# Define rclone config
512512
source_conf "$HESTIA/conf/rclone.backup.conf"
513-
echo -e "$(date "+%F %T") Upload With Rclone: $user.$backup_new_date.tar"
513+
echo -e "$(date "+%F %T") Upload With Rclone to $HOST: $user.$backup_new_date.tar"
514514
if [ "$localbackup" != 'yes' ]; then
515515
cd $tmpdir
516516
tar -cf $BACKUP/$user.$backup_new_date.tar .
517517
fi
518518
cd $BACKUP/
519519

520520
if [ -z "$BPATH" ]; then
521-
rclone copy -v $user.$backup_new_date.tar $HOST
521+
rclone copy -v $user.$backup_new_date.tar $HOST:$backup
522522
if [ "$?" -ne 0 ]; then
523523
check_result "$E_CONNECT" "Unable to upload backup"
524524
fi
525525

526-
backup_list=$(rclone lsf $HOST | cut -d' ' -f1 | grep "^$user\.")
526+
# Only include *.tar files
527+
backup_list=$(rclone lsf $HOST: | cut -d' ' -f1 | grep "^$user\." | grep ".tar")
527528
backups_count=$(echo "$backup_list" | wc -l)
528529
backups_rm_number=$((backups_count - BACKUPS))
529530
if [ "$backups_count" -ge "$BACKUPS" ]; then
@@ -538,7 +539,8 @@ rclone_backup() {
538539
check_result "$E_CONNECT" "Unable to upload backup"
539540
fi
540541

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

0 commit comments

Comments
 (0)