Back to Blog Posts

Automated Backups in WHMCS

By Matt / October 30th, 2019


Hundreds of businesses fail every month due to data loss.

It's all too easy to put off thinking about backups until it is too late, but ignoring backups puts your business and livelihood at risk.

With the built-in backup options in WHMCS, it's quick and easy to configure automated daily backups that mean you're prepared for when disaster strikes.

WHMCS supports 3 automated backup methods out of the box. They are:
  • cPanel Backups
  • Secure FTP Backups
  • Email Backups
In this blog article, we will explore each of the available backup solutions as well as demonstrate how you can set up backups outside of the product using a simple bash script.

So let's get started.
cPanel Backups
If you host your WHMCS installation on a cPanel box, then the built-in cPanel Backups feature is the recommended solution for backing up your WHMCS installation.

Using this backup feature, WHMCS will initiate a full file and database backup of your WHMCS installation by generating a backup of the entire cPanel account that hosts WHMCS daily, and transfer it to a destination of your choice. The destination can be local on the same server, or a remote location using Secure Copy (SCP). We recommend the latter for greater security and protection.

It's easy to set up and simply requires API credentials for the cPanel web server and the username of the account within which your WHMCS installation is hosted.

Summary
  • Easy to setup
  • Works well for larger installations with lots of data
  • Backs up files and database giving you a complete backup
  • Backup process is run in the background
Secure FTP Backups
If your WHMCS installation is hosted on a server which doesn't have cPanel available, then Secure FTP Backups is the recommended alternative.

Using this backup option, WHMCS will generate a dump of your WHMCS installation database daily, and securely FTP this to a destination of your choice. Note that with this method, it is only the database that is backed up automatically, and so you will need to ensure you have a backup of the files from the filesystem separately.

Summary
  • Works without cPanel
  • Database only - does not backup files
  • Can take some time to complete for larger installations with lots of data
  • Can be affected by PHP memory and time execution limits
Email Backups
We no longer recommend using email backups for security and performance reasons, but if you have only a development installation or no other server which you can use for backups, then email might be an option.

With email backups, as with Secure FTP, WHMCS will generate a dump of your WHMCS installation database daily and then deliver it to an email address you define. Like with Secure FTP, this only provides database backups and therefore you should ensure you are taking file backups via another means.

Summary
  • Works without cPanel
  • Database only - does not backup files
  • Can take some time to complete for larger installations with lots of data
  • Can be affected by PHP memory and time execution limits
  • Sending via email can be a potential security risk
External Backups
For a business-critical system such as WHMCS, it is always good practice to have more than one backup strategy in place. This way, should anything ever go wrong with your primary backup solution, you have another backup available to use.

For that reason, we always recommend performing additional backups in addition to the ones offered within the product.

There are many 3rd party backup solutions available that work both at an account or server level such as JetBackup, Acronis, CodeGuard and many more. Alternatively, a simple bash script can be created and configured via cron to run periodically and deliver backups to a destination of your choice. In the example below, we copy the resulting database dump to a remote server, but it could just as easily be configured to upload to an S3 bucket, DigitalOcean Space, or any other storage solution of choice.

#!/bin/bash 

BACKUP_DESTINATION=user@backups.example.com:$(date "+%Y-%m-%d_%H:%M:%S").sql.gz
MYSQL_HOST=localhost
MYSQL_USER=backupuser
MYSQL_DBNAME=whmcs_live1
MYSQL_DBPASS=secretPa$$word

mysqldump -h $MYSQL_HOST -u $MYSQL_USER -p$MYSQL_DBPASS $MYSQL_DBNAME > backup.sql
tar -czvf backup.sql.gz backup.sql
scp backup.sql.gz $BACKUP_DESTINATION
rm -f backup.sql backup.sql.gz

Backups are a vital part of business continuity and disaster recovery planning, and if you aren't taking regular backups, you should start today. To configure backups within WHMCS, navigate to Setup > Other > Database Backups to get started.

What's more, you need to know the backups are good, so testing your backups is equally as important as taking them. We make available free development licenses to all direct license holders, and dev licenses are available for just a small one-time fee for customers of resellers, which are perfect for using to test your backup recovery procedure.

We hope you found this article useful and if you have any questions or comments, we invite you to ask them in the comments below.

Liked this article? Share it