Skip to content

Commit df78931

Browse files
committed
Fix for better backup.conf cleaning
1 parent 253e28e commit df78931

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

bin/v-backup-user

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,8 @@ TIME=$(date +%T)
536536

537537
# Defining local storage function
538538
local_backup(){
539-
# Removing dublicate for this day
540-
if [ -e "$BACKUP/$user.$DATE.tar" ]; then
541-
deprecated="$DATE"
542-
rm -f $BACKUP/$user.$DATE.tar
543-
fi
539+
540+
rm -f $BACKUP/$user.$DATE.tar
544541

545542
# Checking retention
546543
backup_list=$(ls -lrt $BACKUP/ | awk '{print $9}' |grep "^$user\.")
@@ -549,10 +546,9 @@ local_backup(){
549546
backups_rm_number=$((backups_count - BACKUPS))
550547
(( ++backups_rm_number))
551548

549+
# Removing old backup
552550
for backup in $(echo "$backup_list" | head -n $backups_rm_number); do
553-
# Removing old backup
554551
backup_date=$(echo $backup | sed -e "s/$user.//" -e "s/.tar$//")
555-
deprecated="$deprecated $backup_date"
556552
echo -e "$(date "+%F %T") Roated: $backup_date"
557553
msg="$msg\n$(date "+%F %T") Rotated: $backup_date"
558554
rm -f $BACKUP/$backup
@@ -672,7 +668,6 @@ ftp_backup() {
672668
backups_rm_number=$((backups_count - BACKUPS + 1))
673669
for backup in $(echo "$backup_list" | head -n $backups_rm_number); do
674670
backup_date=$(echo $backup | sed -e "s/$user.//" -e "s/.tar$//")
675-
deprecated="$deprecated $backup"
676671
echo -e "$(date "+%F %T") Roated ftp backup: $backup_date"
677672
msg="$msg\n$(date "+%F %T") Roated ftp backup: $backup_date"
678673
ftpc "cd $BPATH" "delete $backup"
@@ -704,7 +699,6 @@ for backup_type in $(echo -e "${BACKUP_SYSTEM//,/\\n}"); do
704699
done
705700

706701
# Removing tmpdir
707-
cd /
708702
rm -rf $tmpdir
709703

710704
# Calculation run time
@@ -729,14 +723,11 @@ msg="$msg\n$(date "+%F %T") Runtime: $run_time $min"
729723
# Vesta #
730724
#----------------------------------------------------------#
731725

732-
# Deleting old backup records
733-
for backup_record in $deprecated; do
734-
if [ -e "$USER_DATA/backup.conf" ]; then
735-
sed -i "/DATE='$backup_record/d" $USER_DATA/backup.conf
736-
fi
737-
done
726+
# Removing duplicate
727+
touch $USER_DATA/backup.conf
728+
sed -i "/$user.$DATE.tar/d" $USER_DATA/backup.conf
738729

739-
# Concatenating string
730+
# Regestering new backup
740731
backup_str="BACKUP='$user.$DATE.tar'"
741732
backup_str="$backup_str TYPE='$BACKUP_SYSTEM' SIZE='$size'"
742733
backup_str="$backup_str WEB='${web_list// /,}'"
@@ -747,9 +738,13 @@ backup_str="$backup_str CRON='$cron_list'"
747738
backup_str="$backup_str UDIR='${udir_list// /,}'"
748739
backup_str="$backup_str RUNTIME='$run_time' TIME='$TIME' DATE='$DATE'"
749740
echo "$backup_str" >> $USER_DATA/backup.conf
741+
742+
# Removing old backups
743+
tail -n $BACKUPS $USER_DATA/backup.conf > $USER_DATA/backup.conf_
744+
mv -f $USER_DATA/backup.conf_ $USER_DATA/backup.conf
750745
chmod 660 $USER_DATA/backup.conf
751746

752-
# Clean backup queue
747+
# Deleting task from queue
753748
sed -i "/v-backup-user $user /d" $VESTA/data/queue/backup.pipe
754749

755750
# Send notification

0 commit comments

Comments
 (0)