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

#The directory where the backup file is located
backup_dir="backup"

#Switch to backup directory
cd "$backup_dir"

#Search for all backup files and categorize them by user
shopt -s nullglob
for user_tar in *.tar;  do
#Get the user name (the part before the first dot in the file name)
user_name="${user_tar%%.*}"

#If there are multiple files, find the latest file (by modification time)
latest_backup=$(ls -t "${user_name}."*.tar | head -n 1)

#If there are old backup files, delete them
if [[ -n "$latest_backup" ]];  then
Echo "Keep the latest backup: $latest_mackup"
#Use ls to search for all backup files except for the latest backup
for old_backup in ${user_name}.*.tar;  do
if [[ "$old_backup" != "$latest_backup" ]];  then
Echo "Delete old backup: $old_mackup"
rm -f "$old_backup"
fi
done
fi
done

#Turn off the null globe option
shopt -u nullglob

Echo "Cleanup completed. "

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