cPanel® Blog

cPanel & WHM Custom Backup Transport Example: Dropbox

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
Now that we have the CPAN module installed, take the time to briefly read over the custom transport documentation to familiarize yourself with the system. Once done, read over the template files we ship with cPanel, located at `/usr/local/cpanel/scripts/custom_backup_destination.pl.sample‘ and `/usr/local/cpanel/scripts/custom_backup_destination.pl.skeleton‘.
Keep in mind that since we ship both the sample and skeleton files, direct edits to these files will be overwritten during nightly updates! Be sure you do not use the same file path as these templates. During the CPAN installation for WebService::Dropbox, you may be prompted to answer “Do you want to install it permanently?”  Since these are relatively small modules and having them installed will help with future CPAN module installations, so I chose “yes” for each prompt.

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
git clone https://github.com/CpanelInc/backup-transport-dropbox.git
cp -av backup-transport-dropbox/backup_transport_dropbox.pl /usr/local/bin/
With your favorite text editor, take the Dropbox credentials you saved earlier and update the MY_APP_KEYMY_APP_SECRET, and MY_ACCESS_TOKEN placeholders.

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!


A quick note: Content just like this will be the norm at this year’s cPanel Conference. If you haven’t already, join us in our semi-official cPanel Discord or Slack, or come to visit Houston, Texas for the 2018 cPanel Conference, October 1st – 3rd.

benny Vasquez

scripter, crafter, cPanel's Manager of Community Engagement. Facilitating communication between cPanel's amazing development team, and cPanel's amazing community. Find me on twitter: @cpaneldev