Create cPanel Account Backups on Dropbox

Issue: cPanel / WHM server, requiring account backups to be created, copied to DropBox, and then created backups removed off the server. Each account backup should be in its own directory on Dropbox.

Solution: Dropbox Master Uploader provided on GitHub: https://github.com/andreafabrizi/Dropbox-Uploader and adapting script originally documented at: http://www.adminsehow.com/2014/08/backup-cpanel-accounts-to-dropbox/

SSH to server as root then:

cd src
wget https://github.com/andreafabrizi/Dropbox-Uploader/archive/master.zip
unzip master.zip
cd Dropbox-Uploader-master

Give execution permission:

chmod +x dropbox_uploader.sh

Run installer:

./dropbox_uploader.sh

This is the first time you run this script, please follow the instructions:

  1. Open the following URL in your Browser, and log in using your account: https://www.dropbox.com/developers/apps
  2. Click on “Create App”, then select “Dropbox API app”
  3. Now go on with the configuration, choosing the app permissions and access restrictions to your DropBox folder
  4. Enter the “App Name” that you prefer (for example: SomeName-NoSpaces)

Click on the “Create App” button.

When your new App is successfully created, please click on the Generate button, under the ‘Generated access token’ section, then copy and paste the new access token, that will look something like:

App folder

– Access to a single folder created specifically for your app.

SomeName-NoSpaces

Token:
7rK9yi-X2_cABCDFGAKVHFv7o2H-rlA6FrZEeGFUK7RzeQMQq-bqYrqbaCCCG6ZB

Now copy dropbox_uploader.sh to /usr/bin

cp dropbox_uploader.sh /usr/bin

Go to directory and test:

cd /usr/bin
dropbox_uploader.sh info

Output should look something like:

Name: John Doe
UID: dbid:CCAeXz5c-XUEp9g-TBbeQ3xxXXXyJe432tc
Email: someaccount@somedomain.com
Country: SE

We need a script that takes the backups and facilitates the transfer.

Let’s make a file:

touch back2dropbox

and create the script:

nano back2dropbox
#!/bin/bash
for fn in $1; do
/scripts/pkgacct $fn
/usr/bin/dropbox_uploader.sh mkdir /cpanel-backup/backup-$fn
/usr/bin/dropbox_uploader.sh upload /home/cpmove-$fn.tar.gz /cpanel-backup/backup-$fn/cpmove-$fn.tar.gz
rm /home/cpmove-$fn.tar.gz
done

Give execution permission:

chmod +x back2dropbox

Test one backup:

back2dropbox 'accountname'

Now try more than one:

back2dropbox 'accountname1 accountname2'

Now that it works, set a cronjob for daily backups:

crontab -e
0 0 * * * /usr/bin/backup2db 'accountname1 accountname2 accountname3' > /dev/null 2>&1

Source file (in case it’s removed from GitHub): Dropbox-Uploader-master

Leave a comment

BlogLogistics