loading
img-bg

Hostiso - hosting for you!How to remove cPanel users backups?

homepage - blog


In this tutorial we will help you to clean up your server from old user backups. cPanel users can generate backups of their accounts. These backups are saved in the root of users’ directories, like /home/username/backup.tar.gz.

The filename format of the backups is backup-date_time_username.tar.gz. For example: backup-7.12.2018_19-32-49_hostiso.tar.gz
The issue is that these backups take disk space and at some point you may see that your server is low on disk space. So, it’s a good idea to remove these backups from time to time.

We recommend to notify your clients that you are removing backups (older than 7 days etc.)

If you wish to remove backups for one cPanel account, just navigate to the user’s directory and remove them with the command:

rm /home/username/backup-*.tar.gz

Usage example:

root@web [/]#
root@web [/]# cd home/hostiso
root@web [/home/hostiso]# ls backup-*.tar.gz
backup-7.12.2018_19-32-49_hostiso.tar.gz  backup-7.12.2018_19-32-49_hostiso.tar.gz
root@web [/home/hostiso]# rm /home/hostiso/backup-*.tar.gz
rm: remove regular file '/home/hostiso/backup-6.11.2017_09-52-31_hostiso.tar.gz'? y
rm: remove regular file '/home/hostiso/backup-6.11.2017_09-52-35_hostiso.tar.gz'? y
root@web [/home/hostiso]#

To find and list all the backups from users’ directories:

find /home/* -maxdepth 1 -type f -name 'backup-*.tar.gz'

To find and delete all the backups from users’ directories:

find /home/* -maxdepth 1 -type f -name 'backup-*.tar.gz' -delete

To find and list all the backups from users’ directories which are older than 7 days:

find /home/* -maxdepth 1 -type f -mtime +7 -name 'backup-*.tar.gz'

To find and delete all the backups from users’ directories which are older than 7 days:

find /home/* -maxdepth 1 -type f -mtime +7 -name 'backup-*.tar.gz' -delete

You can create a con job for this task and automate all.
1.Enter the cron job editor:

crontab -e

2. Add the cron job (this job will run every day at 04:00 and will delete all backup archives older than 5 days)

* 4 * * * find /home/* -maxdepth 1 -type f -mtime +5 -name 'backup-*.tar.gz' -delete

3. Exit (with saving the changes) the cron job editor.

4. Check if the cron job was added successfully with the command (it will list all cron jobs):

crontab -l

That is all, we hope this will help you to save space and maintain your server easily.


Search
Request Tutorial
Need tutorial, contact us ...