cPanel users can generate backups of their accounts. Such backups are kept in the root of users’ directories, like /home/username/backup.tar.gz.
Check the KB post Generate, download and restore backups in cPanel
The filename format of the backups is backup-date_time_username.tar.gz. Example: backup-6.11.2017_09-52-35_plothost.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.
You may want to inform your clients that you are removing backups (older than 5days etc.)
To remove backups for a single 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/plothost
root@web [/home/plothost]# ls backup-*.tar.gz
backup-6.11.2017_09-52-31_plothost.tar.gz backup-6.11.2017_09-52-35_plothost.tar.gz
root@web [/home/plothost]# rm /home/plothost/backup-*.tar.gz
rm: remove regular file '/home/plothost/backup-6.11.2017_09-52-31_plothost.tar.gz'? y
rm: remove regular file '/home/plothost/backup-6.11.2017_09-52-35_plothost.tar.gz'? y
root@web [/home/plothost]#
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 5 days:
find /home/* -maxdepth 1 -type f -mtime +5 -name 'backup-*.tar.gz'
To find and delete all the backups from users’ directories which are older than 5 days:
find /home/* -maxdepth 1 -type f -mtime +5 -name 'backup-*.tar.gz' -delete
You can create a con job for this task.
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
Hello,
How to create a daily Cron Job to delete backup files stored in the Home Directory- .tar.gz ?
Thanks
Hello Rajesh,
There are steps in the article on how to set the command as a corn job.