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, …

Spread the love

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.

Facebook Comments

More Stuff

Keep Email Abuse Off Your Machines Web hosts are businesses. While there isn’t necessarily a tangible brick-and-mortar storefront, a Web Host’s servers are the operating centers for th...
Development Update: 58 is coming, and 60 is beginning! This month was good to the cPanel development team. With cPanel & WHM version 58 in CURRENT, we’re laser focused on fixing bugs and building new f...
2012-06-18 Update Our last article brought you up to date on some aspects of our localization efforts. However the team working on integration with the translation serv...
PHP 7 Is Here! One of our most requested features is for PHP 7 support.  We’ve heard you loud and clear, and over the last few weeks we’ve been working to bring PHP...
Spread the love

Posted by News Monkey