The disk space was running low, so I checked the folders taking up space on my VPS server. I noticed that there are 32 folders inside the /root/hst_backups directory, and they are occupying space. “Last change” is between 2021 and 2022 years.
I don’t know their purpose. Would deleting them cause any issues?
Those folders are Hestia’s conf backups made before the Hestia’s upgrade to a new version. If you don’t need those backups, you can remove them, no problem but those backups should take up little space.
This is a scheduled task that I use to automatically delete backups. Perhaps we can consider adding it to future updates
#!/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 '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] $1" | tee -a "$LOG_FILE"
}
cd "$backup_dir" || { log_message "Error: Unable to enter backup directory $backup_dir"; exit 1; }
shopt -s nullglob
delete_count=0
log_message "════════Starting to clean up backup files════════"
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 the 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 "Deleted a total of $delete_count old backup files."
log_message "════════════════Cleanup completed════════════════"
Starting to clean up backup files
Keep the latest backup: admin. 2022-11-17_05-10-02.tar
Delete old backup:
admin.2024-11-16_05-10-03.tar
Keep the latest backup: admin. 2022-11-17_05-10-02.tar
Delete old backup:
Keep the latest backup: www.2024-11-17_05-10-11.tar
Delete old backup:
www.2024-11-16_05-10-17.tar
Keep the latest backup: www.2024-11-17_05-10-11.tar
Delete old backup:
Two old backup files were deleted in total.
Cleaning completed.