Can I delete folders inside hst_backups?

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.

2 Likes

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════════════════"

I tweaked it and now it should work!

The op is asking for other backups.

Hestia already rotate the backups, there is no need to remove them manually, indeed you will have an inconsistent list of backups for your users.

You should use the full path /backup

All the Echo commands you have in the script won’t work, Echo command doesn’t exist, replace it by echo

1 Like

It is currently working normally

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.

This is the received email report

If you are using the same script you posted, it is not working:

# ./clean_backups
./clean_backups: line 7: cd: backup: No such file or directory
./clean_backups: line 34: Echo: command not found
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.