Deleting a backup after recovery

Hello. After restoring a backup copy, is it deleted from the server after a period of time? This applies to remote backups via FTP, where the server downloads the copy from the remote server and restores it. It seems that after restoration, the /backup folder is not deleted.

When i do migrations, using the v-restore command i will need to delete the original backup i uploaded. After restoring the backup it won’t auto delete it.

I’m not talking about migration. I’m talking about restoring a copy stored on a remote FTP server via a web interface.

You can create an executable script (e.g., v-delete-backups) in the /etc/cron.daily/ directory. It will automatically run every day at 6:25 AM (the exact time depends on your system’s crontab configuration), without needing to add a separate scheduled task in the Hestia Control Panel.

:warning: Notes:

  • The script must have executable permissions: chmod +x /etc/cron.daily/v-delete-backups
  • The script filename should not include an extension (e.g., .sh)
  • The script must start with a shebang: #!/bin/bash

Below is a reference script. Please adjust it according to your actual environment.

#!/bin/bash

backup_dir=“/backup”
current_month=$(date ‘+%Y-%m’)
LOG_FILE=“$backup_dir/v-purge-backups-${current_month}.log”

log_message() {
local timestamp=$(date '+%b %d %Y %H:%M:%S')
echo “[$timestamp] $1” | tee -a “$LOG_FILE”
}

cd “$backup_dir” || { log_message “Error: Cannot enter backup directory $backup_dir”; exit 1; }
shopt -s nullglob
delete_count=0

log_message “════════ Starting backup file cleanup ════════”
declare -A processed_users

for user_tar in .tar; do
user_name="${user_tar%%.}"
if [[ -v processed_users[$user_name] ]]; then
continue
fi
processed_users[$user_name]=1
latest_backup=$(ls -t “${user_name}.”.tar 2>/dev/null | head -n 1)
if [[ -n “$latest_backup” ]]; then
log_message “Keeping latest backup: $latest_backup”
old_backups=()
for old_backup in ${user_name}..tar; do
if [[ “$old_backup” != “$latest_backup” ]]; then
old_backups+=(“$old_backup”)
fi
done
if [[ ${#old_backups[@]} -gt 0 ]]; then
log_message “Deleting the following old backup files:”
for old_backup in “${old_backups[@]}”; do
log_message " - $old_backup"
rm -f “$old_backup”
((delete_count++))
done
else
log_message “No old backups to delete for user $user_name”
fi
fi
done
shopt -u nullglob
log_message “Total $delete_count old backup files deleted”
log_message “════════════ Cleanup completed ════════════”

It’s a good script, but I think this functionality should be implemented at the panel level.

The control panel requires a separate task scheduler for each task to run. This script is placed in /etc/cron.daily/ because the system is configured to run it automatically by default. No separate timer needs to be added.