START here

cPanel reseller hosting backup automation

In this article, I’m explaining how I’ve configured automated backups of all the websites (cPanel accounts to be precise) under my cPanel reseller hosting accounts (what is reseller hosting). This tutorial will be easy to follow if you at least know the basics of working with cPanel.
You can use this tutorial to configure automated backups for shared hosting accounts as well (what is shared hosting). Just, instead of the WHM username and password, use your cPanel username and password, and instead of WHM server address and port, use your cPanel server address and port.
A separate post explains DirectAdmin reseller hosting account backup automation.

Table Of Contents (T.O.C.):

  1. Introduction
  2. WHM Backup Solutions and its alternatives
    2.1. WHMEasyBackup (WHMEZBACKUP)
    2.2. WHM Backup Solutions – free open source
  3. Configuring automated backups
    3.1. Backup storage – Hetzner Box
    3.2. PHP path of your main cPanel reseller account
    3.3. Your WHM server address and port
    3.4. Your WHM login username and password
    3.5. Copying WHM Backup Solutions to your hosting server
    3.6. Configuring WHM Backup Solutions
    3.7. Cron job creation – backup automatization
  4. Troubleshooting
  5. SFTP connection problems
  6. Conclusion


1. Introduction

Several decades of working with computers have taught me that when it comes to backups, it can be said that “one is like none.” In other words, anything important should be kept in at least two different, separate places.

When does data usually get damaged? A minute before the next planned backup.

Because of that, in addition to the backups created by the hosting provider, I make sure to have at least one more backup copy of my own (two in fact), on completely separate storage.

I used to do that using JetBackup, but since the last update, it no longer makes backups that I can easily test and confirm to be good (see: JetBackup reseller hosting backups for detail). Hence I started looking for alternative solutions.

After a lot of investigating and testing, I’ve had the best results with WHM Backup Solutions (link to their website).

– T.O.C. –


2. WHM Backup Solutions and its alternatives

After realising that JetBackup no longer makes backups I can test, edit and use independently of the hosting provider, I started looking for alternatives.


2.1. WHMEasyBackup (WHMEZBACKUP)

The first solution that came to mind was the WHMEasyBackup (link to their website). It had come highly recommended on the WebHostingTalk forum (link to the forum) by several hosting providers. I already had two lifetime licenses (bought in 2019) and kept just in case JetBackup ever gets any hiccups.

I knew there are free, open-source alternatives, but my reasoning was that a paid solution could be more reliable, with the provided technical support, maintenance etc.

To my surprise, it turned out my lifetime licenses have been turned to “legacy licenses,” not supporting the latest software version. Well, that hadn’t been clearly stated at the time of purchase. That doesn’t sound like a fair business policy to me.

Now, they do claim the old software version still works and they will also update the old version if cPanel drastically changes. However, it didn’t work for me.

Instead of spending quality time with the hosting provider, and WHMeasyBackup technical support (see what I call the “Catch-22 paradox“), I decided to try a free open-source alternative – and that worked great! 🙂

– T.O.C. –


2.2. WHM Backup Solutions – free open source

WHM Backup Solutions turned out to be a good solution. In this article, I’ll explain how I’ve configured automated backups of my reseller hosting accounts using this software.

This is a free, open-source solution maintained by mister Peter Kelly – thank you very much. 🙂

– T.O.C. –


3. Configuring automated backups

Without further ado, here’s a step-by-step tutorial of how to configure automated backups of your cPanel reseller hosting accounts. For that we’ll need the following data (I’ll explain how to get them):

  1. FTP server address, username and password
  2. PHP path of your reseller hosting account
  3. Your WHM server address and port
  4. Your WHM login username and password
  5. WHM Backup Solutions directory path


3.1. Backup storage – Hetzner Box

In a separate article, I’ve explained in detail how to “buy” and configure Hetzner Storage Box storage – “Hetzner Storage Box explained.”

I suggest you follow the instructions given there if you choose to use Hetzner for your backup storage. Pay attention to the 6th chapter – “Creating additional FTP user accounts,” because that’s what we’ll be using here.

Write down your FTP server address, username, password (see picture 7 and read chapter 6 in the above-linked article), and keep in mind that Hetzner Storage Box uses port 21 for FTP, and port 23 for SCP.

That may look like:

  • FTP server address: u273500.your-storagebox.de
  • Username: u273500-sub1
  • Password: DSjk04#$9sdf3J0s2l

Of course, you can use any other (S)FTP storage – the principle is the same.

– T.O.C. –


3.2. PHP path of your main cPanel reseller account

Log into the main cPanel account of your reseller hosting, and set the PHP version to 7.4 (if that’s not available, look for a better hosting provider).

Create a file “phpinfo.php” (or download it from BikeGremlin – phpinfo.php.zip) containing this code:

<?php
phpinfo(INFO_GENERAL);
echo '<br /><br /><strong>Path To PHP:  </strong>'.PHP_BINDIR.'/php';
?>

If you wish to see a list of all the active PHP extensions, add this line of code before closing the PHP (i.e. before the “?>” line):

phpinfo( );

Now log into the main cPanel account of your reseller hosting account and upload the “phpinfo.php” file to the public_html directory (unzip it if you’ve used the BikeGremlin download).
Yes, of course, you can do this via an FTP client as well.

Then use a browser to visit your main cPanel reseller hosting account’s web address and add “/phpinfo.php” at the end, like:
https://www.your-reseller-account-domain.com/phpinfo.php

Your cPanel reseller hosting account PHP path - write it down
Your cPanel reseller hosting account PHP path – write it down
Picture 1

– T.O.C. –


3.3. Your WHM server address and port

Log into your WHM account using the hosting provider’s portal.

WHM login. Your hosting provider's control panel may look different, but the principle is the same
WHM login
Your hosting provider’s control panel may look different, but the principle is the same
Picture 2

After you’ve clicked and logged in to the WHM, write down the server’s web address and port number as shown in your browser.

WHM server address and port number
WHM server address and port number
Picture 3

In this case, WHM server address is “cp3.fastestserver.co.uk” and its port is “2087”.

– T.O.C. –


3.4. Your WHM login username and password

These are the username and password you use for logging into your WHM (and your main reseller hosting cPanel account).

You should know these – and have them stored in an encrypted KeePass file.

– T.O.C. –


3.5. Copying WHM Backup Solutions to your hosting server

First things first – you should download the latest version of WHM Backup Solutions software (their website link).

You could also download it from BikeGremlin download – on that copy I’ve already created a directory, created the needed “config.php” file to work with this tutorial containing edits like:

$config['whm_username'] = 'see chapter 3.4';

instead of:

$config['whm_username'] = '';

If you are using the BikeGremlin download version, just upload the file to the root directory of your main reseller hosting cPanel account. If you are using the original download, you must first create a directory “whmbackupsolutions” and upload the file there. Again: in the root directory, not in the “public_html”.
Actually, you can name the directory however you like it, but in this tutorial we’ll be using “whmbackupsolutions”. If you name the directory differently, you’ll have to make more edits when copy/pasting the commands. Directory names and paths are case-sensitive, so pay attention (“WhmBackupSolutios” is different from “whmbackupsolutions”).

Select the root directory (1) and choose upload (2)
Select the root directory (1) and choose upload (2)
Alternately, if you are using the original file (not the BikeGremlin download), first create the “whmbackupsolutions” directory (3), then upload the file there
Picture 4

Unpack the file after you’ve uploaded it.

Write down the path to where you’ve copied all the files. In our example that is:
/home/bikegremlin/whmbackupsolutions/
For you it could be:
/home/your-username/whmbackupsolutions/

– T.O.C. –


3.6. Configuring WHM Backup Solutions

As shown in picture 5 below: go to the “whmbackupsolutions” directory (1), right-click on “config.php” file (2) and select the “Edit” option (3). If you are not using the BikeGremlin download, you will need to copy the file “config.php.new” into “config.php” (2a), because “config.php” doesn’t exist in the original version.

cPanel text file editing option
cPanel text file editing option
Picture 5

In the “config.php” file, edit the needed fields to match your server and accounts (as explained in chapters 3.1 through 3.5). Let’s summarize the needed info:

  1. FTP server address, username and password
  2. PHP path of your reseller hosting account
  3. Your WHM server address and port
  4. Your WHM login username and password
  5. WHM Backup Solutions directory path

The “config.php” file has descriptive comments before every field, with my version being even more simplified for containing the references to the chapters of this tutorial, and all the default values pre-set to work with FTP transfer to a Hetzner Storage Box.

Edit the fields based on your data - it's pretty straight-forward
Edit the fields based on your data – it’s pretty straight-forward
Picture 6

– T.O.C. –


3.7. Cron job creation – backup automatization

A brief digression explaining cron job basics – until I write a detailed article about them. If you wish to go straight to the cron job examples, click here to skip the explanation.

My smartphone allows me to configure an alarm, that goes off every workday (Monday through Friday) at 15:30 (waking me up, so I’m not late home from work 🙂 ).

When you configure something like this on a server, running the Linux operating system, it’s called a “cron job.”

  • What does a cron job do? Basically, whatever you program it to.
  • When does it run? Whenever you schedule it to run – every 10 minutes, every second hour, every Tuesday, 15th of a month at 13:43…

In this case, we’ll use cron jobs to automate WHM Backup Solutions backups. This software requires two cron jobs:

  1. Cron job 1 that reads the “config.php” file (chapter 3.6) and based on its settings “says” what needs to be backed up and where to. This is done in seconds.
  2. Cron job 2 that creates a backup and uploads it to a location (as instructed). If you are backing up a large account (over 2 GB in size), this can take about 30 minutes.

Let me explain how this works using an example:

  • Say we’ve configured “config.php” to back up all the cPanel accounts to our FTP server.
  • And let’s say we have a total of 12 cPanel accounts on our reseller hosting account.
  • When cron job 1 runs, it will tell WHM Backup Solutions program: “OK, back up these 12 cPanel accounts to this FTP server.”
  • After that, when cron job 2 runs, it will back up the first cPanel account from the list and mark that one as done. In order to back up the remaining 11 cPanel accounts, cron job 2 needs to be run at least 11 more times. After all the backups scheduled by cron job 1 have been backed up, running the cron job 2 again will only state: “I’ve got nothing left to do, bye.”

Why is this important? Well, if you want to make daily backups, and you have 50 cPanel accounts to back up, you’ll need to schedule cron job 2 to run at least 50 times in a day, before cron job 1 is run again, the next day. This means you’d need to schedule cron job 2 to run every 30 minutes, every day.

If this is done on a shared hosting server, with many users, running cron jobs that put a big load on the server (like backup jobs can do) can slow the server down. Some hosting providers put limits on how many cron jobs you are allowed to run per day, or even per hour (HostMantis provider allows only one cron job per hour).

Likewise, if there are too many total cron jobs scheduled, and the server is loaded, it will put them in a waiting queue, doing them when it can. So scheduling cron jobs too often could result in having a longer and longer queue, with the most recently scheduled cron job having to wait for all the jobs that are in queue to be finished before it gets run.

In this example, we’ll configure cron job 1 to run every week, on a Monday, at 6 minutes past midnight. Cron 2 will be run once per hour, every Monday, starting at 01:06, through 23:06. This suffices for up to 23 cPanel accounts backup. If we had more accounts, we’d need to schedule cron 2 to run on both Monday and Tuesday from 1:06 to 23:06.


The info needed to configure cron jobs for automating backups:

  1. FTP server address, username and password
  2. PHP path of your reseller hosting account
  3. Your WHM server address and port
  4. Your WHM login username and password
  5. WHM Backup Solutions directory path

Based on this data, you will create the two cron jobs.

Cron job 1:

/your-server-php-path/ -q /your-whm-backup-solutions-path/whmbackup.php generate

In this example:

/opt/cpanel/ea-php74/root/usr/bin/php -q /home/bikegremlin/whmbackupsolutions/whmbackup.php generate

Cron job 2:

/your-server-php-path/ -q /your-whm-backup-solutions-path/whmbackup.php

In this example:

/opt/cpanel/ea-php74/root/usr/bin/php -q /home/bikegremlin/whmbackupsolutions/whmbackup.php

Copy/paste these two cron jobs into a text editor and edit them to match your paths.
You’ll need this in a minute.

Cron job defining and scheduling is done using cPanel’s “Cron Jobs” tools.

cPanel Cron Job scheduling - at a click of an icon :)
cPanel Cron Job scheduling – at a click of an icon 🙂
Picture 7

After you enter the “Cron Jobs” menu, you’ll configure the desired tasks.

WHM Backup Solutions cron job 1, set to run on Mondays, at 00:06
WHM Backup Solutions cron job 1, set to run on Mondays, at 00:06
Picture 8
WHM Backup Solutions cron job 2, set to run each hour past 6 minutes, from 01 through 23 hours, on Mondays
WHM Backup Solutions cron job 2, set to run each hour past 6 minutes, from 01 through 23 hours, on Mondays
Picture 9

After configuring a cron job and clicking on the “Add New Cron Job” button, that job will be added to the list of cron jobs:

cPanel's list of created (scheduled) cron jobs, containing the basic info for each cron
cPanel’s list of created (scheduled) cron jobs, containing the basic info for each cron
Picture 10

If you have more than 23 cPanel accounts to backup, you can enter “1-3” in the “Weekday” field, making cron job 2 run on Monday, Tuesday and Wednesday, every hour.

Was that hard? There are many steps, so I wrote it down as a reminder, but it’s not really hard, is it?

Check if backups are uploaded, and try restoring websites from the backup copies to confirm the backups are working (do this in a staging environment, not on production websites).

– T.O.C. –


4. Troubleshooting

WHM Backup Solutions makes nice log files stored in the “logs” subdirectory of the program’s install directory. Unlike WHM Easy Backup that doesn’t really help you with troubleshooting (at least I couldn’t figure it out).

WHM Backup Solutions log files location
WHM Backup Solutions log files location
Picture 11

Reports or problems with backup jobs will be shown in the backup log files (2), while any problems with “config.php” entries will be shown in the “system.log” file (3).

– T.O.C. –


5. SFTP connection problems

I’ve got no problems making SFTP connections to Hetzner Storage Box using the FileZilla FTP client. However, I couldn’t get the WHM Backup Solutions (nor WHM Easy Backup for that matter) to run using an SFTP connection. Here’s an error log example:

WHM Backup Solutions (https://whmbackup.solutions) - V1.5
2021-08-15-18:12 - (johnsmith) ERROR: The password that you provided is not correct,
or the SSH key is not permitted access:
ssh: connect to host u273500.your-storagebox.de
port 23: Network is unreachable at /usr/local/cpanel/Cpanel/API/Backup.pm line 182.

If you have a solution or a link to a better tutorial, please share it in the comment section at the bottom of this page.

– T.O.C. –


6. Conclusion

Every system will fail sooner or later, or be hacked (why every website will be hacked). Backups are one of the ways to minimize the damage.

Automated backups are a good idea because they can save you a lot of time and hassle.

Important note:
I hadn’t configured a script to delete old backups. WHM Backup Solutions allows that as well. However, I regularly download backups to my HDD storage (a 2nd copy), and I move them from the FTP directory accessed by the hosting server to a directory hosting server can’t reach (FileZilla drag & drop explained).

This way I’m forcing myself to check if all the backups are running properly (in addition to all the logs).

If you don’t do this, make sure to configure the automated backup deletion, or your storage will get filled up.

– T.O.C. –

6 thoughts on “cPanel reseller hosting backup automation”

  1. Works really well,
    But I have one major issue, after data backup to backup server the data remains on my cpanel.
    This script won’t delete my old backup data archive file after uploaded to backup server.
    If its can’t delete old archive data then this is useless.

    is there any tip or settings to auto remove old achieve data from cpanel?

  2. Hi Arun,

    Did you configure the WHM Backup Solutions to store backups using FTP, or in your homedir
    (“$config[‘backup_destination’] = ‘ftp’;” setting)
    ?

  3. So the created backups are pilling up ond the hosting server, in spite of copies being uploaded to a remote storage via FTP?

    Does this problem stop when no whmbacupsolutions scripts are run (i.e. can we 100% confirm WHM Backup is the culprit)?

    I haven’t had this problem, and at the moment I have no cPanel hosting to check and confirm (maybe new cPanel version is no longer completely compatible with the script).

  4. Yes, exactly

    yes, WHM backup is the culprit

    Can you suggest any other tool ?
    Can I move to Jetbackup?

    • Yes, Jetbackup works fine.
      But, in a shared (and/or reseller) hosting environment, you have to rely on the hosting provider’s technical support to restore the backups.
      I don’t think this is very practical.

      I wrote here about JetBackup.

Comments are closed.


Please use the BikeGremlin.net forum for any comments or questions.

If you've found any errors or lacking information in the article(s) - please let me know by commenting on the BikeGremlin forum.
You can comment anonymously (by registering with any name/nickname), but I think it is good to publicly document all the article additions (and especially corrections) - even if their author chooses to remain anonymous.

Skip to content