How to limit the number of backups users can store locally?

Operating System & Version
CloudLinux 7.8
cPanel & WHM Version
88

andrew.n

Well-Known Member
Jun 9, 2020
982
363
63
EU
cPanel Access Level
Root Administrator
If I'm not mistaken though I'm not 100% sure the local backups counts against the accounts's storage limit so basically the available space is the limiting factor here. Please @cPanelLauren confirm me.
 

Dhrupodi

Well-Known Member
Sep 8, 2019
47
10
8
root
cPanel Access Level
Root Administrator
Hi @andrew.n

Thank you for replying.

I am not referring to the storage.

I am referring to the number of backup files.

For example, a user won't be able to store more than 5 backup files under their account. If they go to create another backup, they will be presented a warning to tell them that backup limit reached and they need to delete at least one file. Or, the cPanel will just delete the oldest backup and store the new backup under their account, maintaining the total count of 5 backup files.
 

andrew.n

Well-Known Member
Jun 9, 2020
982
363
63
EU
cPanel Access Level
Root Administrator
As far as I know there is no option to limit this at the moment.
 

cPAdminsMichael

Well-Known Member
Dec 19, 2016
192
74
153
Denmark
cPanel Access Level
Root Administrator
Hi,
You would be able to do that with fx JetBackup's snapshots. You cannot define the limit per account - but you could group accounts if you want to have a differentiated setup :)
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
The backups, if they are owned by the user will count against the user's storage. There isn't anything native to cPanel that limits backups to a certain number, you'd want to use JetBackup as suggested or create a custom script.

A lot of shared hosting providers allow backups to remain on the account for a certain amount of days. So for example. No backups would be present if older than 7 days.
 

Dhrupodi

Well-Known Member
Sep 8, 2019
47
10
8
root
cPanel Access Level
Root Administrator
A lot of shared hosting providers allow backups to remain on the account for a certain amount of days. So for example. No backups would be present if older than 7 days.
Thank you for replying.

This could be an alternative solution. Would you direct me on how I can do that?

I use JetBackup only and the native backup tool is disabled.

I wanted a way so that users cannot store more than X number of backup files. This would allow a way for the users to keep a backup under their account.
 

Dhrupodi

Well-Known Member
Sep 8, 2019
47
10
8
root
cPanel Access Level
Root Administrator
ou would be able to do that with fx JetBackup's snapshots. You cannot define the limit per account - but you could group accounts if you want to have a differentiated setup
Thank you for replying.

I use JetBackup incremental backup. I want to provide a way for the users to store their account backups under their account, while also limiting them on how many backups they can store.
 

cPAdminsMichael

Well-Known Member
Dec 19, 2016
192
74
153
Denmark
cPanel Access Level
Root Administrator
Thank you for replying.

I use JetBackup incremental backup. I want to provide a way for the users to store their account backups under their account, while also limiting them on how many backups they can store.
I don't think you can configure JetBackup to store the automated/nightly backups under the accounts' own volume, if that's what you ask.
You can, however, configure Snapshots in JetBackup and set limits, and the users would then be able to do ad-hoc backups (snapshots) of their accounts and also restore from those.
 

cPAdminsMichael

Well-Known Member
Dec 19, 2016
192
74
153
Denmark
cPanel Access Level
Root Administrator
@Michael Svendsen

Thank you for replying.

I am not after that feature. What I need is a way to limit the number of cPanel backups a user can store on their account.
Ok, then I'm not 100% sure what you mean and what you want to achive :)
If you are talking about retention policy, both cPanel Backup and JetBackup can be configured to retain only the last x backups. In JetBackup that's done as a schedule:

And likewise in cPanel Backup:
 

Dhrupodi

Well-Known Member
Sep 8, 2019
47
10
8
root
cPanel Access Level
Root Administrator
@Michael Svendsen

Thank you for replying.

What you referred to is the WHM's Automated Backup Tool (apart from JetBackup).

I am referring to the backup tool inside user's cPanel. Though the names are the same, these two tools are much different. WHM's backup tool is used to create and store automated backups. I don't use that, so it remains disabled.

The backup tool inside cPanel is used to manually generate full and partial backups. I want to limit the number of these user-generated backup files that a user can store on their hosting account.
 

cPAdminsMichael

Well-Known Member
Dec 19, 2016
192
74
153
Denmark
cPanel Access Level
Root Administrator
Ahhhhh :)
I don't think you are able to limit the amount of those stored backups, as they will just count towards the users quota anyway.

HOWEVER.... as you wrote that you are using JetBackup - why don't you just use their snapshot feature? It can do the same - and with your limitation wishes ;)
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
You can limit the stored backups but you would need to write a custom script. The script would be fairly simple, but would be easiest to do for a specific time frame. For example:

Code:
find /home/ -name '*.tar.gz' -type f -mtime +7 -exec rm {}
 

Mathan kb

Registered
Aug 20, 2020
1
0
1
chennai
cPanel Access Level
Website Owner
Thank you for replying.

This could be an alternative solution. Would you direct me on how I can do that?

I use JetBackup only and the native backup tool is disabled.

I wanted a way so that users cannot store more than X number of backup files. This would allow a way for the users to keep a backup under their account.
Thanks it was helpful
 

Dhrupodi

Well-Known Member
Sep 8, 2019
47
10
8
root
cPanel Access Level
Root Administrator
@cPanelLauren

Thank you for the hint.

Where do I store the script, and what do I name it?

The script should also have a way to output a message and a variable for cPanel to know whether it should proceed with the backup, or not.

For example, if the script outputs 0, cPanel will proceed with creating a backup. If it outputs 1, cPanel will abort the backup and display a message defined in the script, such as "backup limit exceeded. You can only store five backups. Please delete some backups before creating one."

Or, as in your sample script, it might just delete the oldest backup and proceed with creating a new one. However, if the above can be done, it would be great.

Does cPanel have a native way of executing a specific script right before performing the backup? For example, cPanel might search for a "backup_pre" script in a specific directory, and if the script exists, cPanel would execute it.

Does cPanel have any such feature?
 

Dhrupodi

Well-Known Member
Sep 8, 2019
47
10
8
root
cPanel Access Level
Root Administrator
@Michael Svendsen

cPanel backups and JetBackup backups aren't the same. Only a few cPanel based providers provide JetBackup. I am not interested in JetBackup for this feature.

If there is a third party tool that can limit cPanel backups, that would be awesome, too.

Besides, a cPanel backup can be used to automatically restore the account on any cPanel based server. It is mobile.
 

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
So what I provided is able to be added as a cron job, but you could potentially also write a script that will perform the actions you're suggesting as well. The Guide to Standardized hooks which @andrew.n provided might be helpful in setting this up to complete after a backup job is finished.