The cPanel backup system provides lots of flexibility, and one of its awesome features is the ability to create custom backup transports. In cPanel, a backup transport or destination is a method to move backups to a secondary/remote server for safe keeping. The custom backup transport feature allows you to specify a script which the backup system will pass arguments to; arguments common with uploading files in FTP, e.g. ‘put $filename’. Reading over the documentation, it may at first appear a daunting task; however, today we’ll walk you through the process by creating a backup destination utilizing Dropbox and their very thoroughly documented API.
Setup Dropbox
If you don’t already have a Dropbox account, create one here. Once you have an account, head over to their developer section to create an app (this is required to use their API). You’ll be prompted to select the typical Dropbox API or the Business API. For our testing purposes, we’ll stick with the free Dropbox API. For step two of the app creation process, select Full Dropbox. Finally, set a name for your app; I chose ‘cpanel-backups.’
After creating the Dropbox app, you’ll be redirected to the Settings page for your app, which will provide your API credentials. Keep track of the App Key, and App Secret. Then click the Generate access token button and retain that as well.
Prepare the Server Environment
Now that we have everything we need from Dropbox to configure the custom transport, let’s prepare the server environment. To make things simple, we’ll utilize CPAN WebService::Dropbox. On CentOS 7.4, this installed without complication. However, on CentOS 6, I also needed to install the perl-YAML package.
# CentOS 7
sudo cpan WebService::Dropbox
# CentOS 6
sudo yum -y install perl-YAML
sudo cpan WebService::Dropbox
`/usr/local/cpanel/scripts/custom_backup_destination.pl.sample'
and
`/usr/local/cpanel/scripts/custom_backup_destination.pl.skeleton'
.
Install the script
We understand that not everyone has the time to learn a new programming language, so we’ve done a lot of the heavy lifting for you by uploading our Dropbox custom backup transport script to GitHub. I highly encourage you to look at the script and see what can be done here with just over 100 lines of code. Clone and copy the script into place:
# escalate to root
, if you are not already
sudo su - root
# clone and copy the script from github
cd /usr/local/src
cp -av backup-transport-dropbox/backup_transport_dropbox.pl /usr/local/bin/
Configure the transport in WHM
We’re now ready to configure the transport in WHM. Head over to WHM » Backup » Backup Configuration and scroll down to Additional Destinations. Under Destination Type, select Custom, then Create new destination. Configure the destination as below (note, since we’re using the API keys directly in the transport script, you can enter anything for the host, user, and password):
Be sure to hit Save and Validate Destination at the bottom of the screen.
Get backing up!
Congratulations, you’ve just created your first custom backup transport script, how cool is that?! Feel free to fork us on GitHub and be sure to share with us your custom backup transport scripts!
If you haven’t already, join us in our semi-official cPanel Discord or Slack.