Tinkering the cPanel Backup System

The backup system in cPanel doesn’t do exactly what we want, it does the job pretty well but you can’t set schedules of who wants daily backups and who wants weekly and still handle all the retentions that some hosts need.

I’m not going to cover the legacy cPanel system here (we are migrating away from it), sufficient to say it didn’t support retentions (and we scripted around that), and wouldn’t handle us turning on and off users on daily or weekly backups (or none at all) until we’d mastered hacking the cpbackup-userskip.conf as part of a cron job, but at some point I have to be realistic that this system will be retired.

With the new backup system things are a little different, cPanel DOES support retentions and even how many retentions to hold. This is a massive improvement on where we were but still doesn’t give the granular control we needed on a recent project to assign different users to run on different days, lets look at how we can do that.

Data Source

Firstly you need a good solid data source, in our case this is our billing system which retains details of which users are assigned on to which back up plan.

I’m not going to cover retrieving this information here as it will be different in practically every scenario but suffice to say you need a system that tells you which users on this server are assigned to which backup plan, and you need to cron fetching that on a daily basis BEFORE the backup process begins.

You also need to make this system secure!

Controlling the backup

Note: This is NOT the legacy backup system.

Essentially, you’ll need to loop through the list of users in your data source turning on or off backup users in their config file, you need to update every one as you’ll be turning backups off on 6 days out of 7 for users who only require a weekly backup.

You also need to find customers of resellers who have backups enabled so you ensure you backup their client accounts too /etc/trueuserowners is the key to this, so you can find out which usernames are owned by each reseller.

You then need to update /var/cpanel/users/<username> for each entry, setting “BACKUP=1” or “BACKUP=0” as appropriate:

  • For daily backup customers backup will always be set to 1.
  • For weekly backup customers backup will ONLY be set to 1 on the day you’ve selected as your weekly backup day in WHM

Once you’ve completed all your edits on user config files you need to run the following to rebuild cPanel’s system cache: /usr/local/cpanel/scripts/updateuserdomains

All in all it’s perfectly doable if you’re happy to do a bit of scripting.

Leave a Reply

Your email address will not be published. Required fields are marked *