Automatically backup all cPanel/WHM Accounts to remote SFTP server!
For all the system administrators out there, backing up data is really important job. Because we all know what happens when server crash happen, or a hard disk drive fails. cPanel/WHM is one of the most comercially used software by web hosting companies and individuals. They have a really nice built in system for backing up accounts to following remote locations:
- Amazon S3
Well that is more than enough right ? As you can see you already have the option of FTP and SFTP, what else you may need? But before you continue you need a storage server that can host your backups. You can buy a very cheap storage server from here. ($3.99 euro for 1TB of backup space). Incase you already have storage space you don’t need to buy a seprate storage server.
Well, let see that how we can use WHM to backup all or selected accounts to any of these destinations mentioned above.
Step 1: Select the Accounts to Backup!
WHM let you select which accounts you need to include in the automatic backup process, please see in the image below that how we can do this:
- Search for “backup” in the search box.
- Than select “Backup User Selection” from the list.
- Now on the third arrow, if you want to enable backups for all cPanel accounts you can click “Enable All Backups”.
However if you are not interested to enable backup for all accounts, you can turn them “on” or “off” for each account. Once you are done with user selection, we can configure the backup settings for automatic backups to a remote server.
Step 2: Enable Backups!
Next step is to enable your backups settings, so that backups can be created on daily, weekly or monthly bases.
- Search for “backup” in the search box.
- Than select “Backup Configuration” from the list.
- Now enable the backups as they are enabled in the image above. By default they are disabled so you must enable for backup function to work.
Step 3: Select Backup Type!
- As you can see you have 3 options available, and I’ve selected the first option which is “Compressed”. Now it depends on your setup, if you have less storage space for backups you need to select compressed backup type, however it will put some load on your server for compression to take place.
- If you select uncompressed, it will save all files to the remote server uncompressed, so there is no cpu overheads on the server but than you require more space on the storage server.
- The third option is very new in WHM and which is incremental, you should not select it because with this option you can not store backups to remote locations. This option only works for backups in local directory.
Now it depends on your usecase that which option works best for you.
Step 4: Schedule Backup!
Now we need to select that how often you need to backup your accounts, there are three possible options.
My current settings looks like:
Now it is totally upto your requirments that how often you are interested to backup your accounts.
Step 5: WHM Backup File Related Settings!
These are some miscilinious settings weather you are interested in enabling backups for suspended accounts or you need to store backups for access logs or not, you can leave these settings as they are, my settings looks like:
Step 6: Database backup!
Well this option is an important one, database backups are important to restore the WHM account restore feature.
You must atleast select “Per Account Only” option , this way you can use the backup file directly to restore account from WHM. All you will need to do is upload the backup file in “/home” directory of your cPanel/WHM server and than restore the account from WHM, we will discuss on how to do that in another article.
Step 7: Configure Local Backup Directory!
Before backups are sent to a remote location, they need to be stored at local directory first. You need to specify where WHM should store backups locally, you need to be carefull that this directory should have enough space to accomodate backups.
As you can see that I’ve unchecked the “Retain backups in the default backup directory“, because this will save space on your WHM server, it means once the backups are transferred to a remote location, they will be deleted from your WHM server. But you can always turn it on if you need. 🙂
Step 8: Create Backup Destination
Now this is the step where we need to define a remote server which will house our backups. For that you are going to need a server, with SSH or FTP access. I am going to demonstrate that how you can do this with ssh access, same will apply to ftp server as well.
- From drop down select “SFTP”.
- Than click “Create new destination”.
Following will than appean:
Destination Name: Give any friendly name to your destination.
Backup Directory: Remote backup directory where WHM will send the backups, i.e. /root/backups.
Remote Host: IP Address of the server.
Authentication Type: Password Authentication.
Remote Password: SSH Password of your server.
After filling all these details click “Save and Validate Destination”. It will save the details as well verify the details that you have provided.
Step 9: Finalize the Backup Configuration
Once all the above mentioned steps are completed you can click “Save Configurations” at the end of the main backup configuration window. And we are done, your backups will now be sent to the remote server automatically depending on what scheduled you have choose.
If you have any questions feel free to put them in a question box below.