Admins eHow SysAdmin Tips & Tricks

August 30, 2014

Backup cPanel accounts to DropBox

Filed under: cPanel,linux — Tags: , , , — admin @ 7:30 pm

Notice : You need root access to cPanel server to be able to use this method.
DropBox is my favorite cloud space provider. Their recent price adjustment (1TB for $10/mo) has made using it a no brainer IMO. It is specially very good for backup purposes because it keeps different versions of your files without using any extra space. The retention period for free accounts is 30 days and for pro accounts is 1 year.
So lets say you take a backup of your website and upload it to DropBox everyday and size of your backup is 100MB. if you keep doing it for 1 year, in fact DropBox is keeping 365 x 100MB of your files which you can retrieve any of them while only 100MB of your space is used! it is crazy good, I know.
In order to be able to backup cPanel accounts directly to DropBox, first we need a method to upload files to DropBox from Linux command line. Fortunately there is a very good solution out there to do it :
Please refer to script documentation on how to install it on your server and link it to your DropBox account. it is fairly easy.
After you linked the script to your DropBox Account, move it to /usr/bin folder.
If you want to test it, run the following command and it should show your DropBox account info :

root@X:[~]: info
Dropbox Uploader v0.14

 > Getting info...

Name:   X X
UID:    012345
Quota:  1021760 Mb
Used:   2611 Mb
Free:   1019148 Mb

Now create /usr/bin/backup2db with following content and make it executable :

for fn in $1; do
/scripts/pkgacct $fn
/usr/bin/ upload /home/cpmove-$fn.tar.gz /cpanel-backup/cpmove-$fn.tar.gz
rm /home/cpmove-$fn.tar.gz

Thats it ! We are good to go.
Command to backup cPanel account acct1 :

backup2db 'acct1'

It even support multiple account backup :

backup2db 'acct1 acct2 acct3'

If you need daily backups, you can put it in cron :

0 0 * * * /usr/bin/backup2db 'acct1 acct2 acct3' > /dev/null 2>&1
  • Roger

    Wow! Great solution! 🙂

    Question, What command(s) do I add to ‘backup2db’ so that each account backup is stored on a separate folder inside that Dropbox ‘cpanel-backup’ directory?

    For example:


    Any suggestion or help would be appreciated,
    Thank you!

  • Roger

    For anyone coming after me and reading this, here’s how to get individual Dropbox directories for each account:

    for fn in $1; do
    /scripts/pkgacct $fn
    /usr/bin/ mkdir /cpanel-backup/backup-$fn
    /usr/bin/ upload /home/cpmove-$fn.tar.gz /cpanel-backup/backup-$fn/cpmove-$fn.tar.gz
    rm /home/cpmove-$fn.tar.gz

  • Brian Spotts

    Awesome solution! You’re saving me money every month by not storing backups on my VPS, and using some of the space on dropbox that I spend $9.99/mo on, and barely use 2% of the 1TB in my plan. Thanks!

    One question; is it possible to set up a cron job that would ‘retain’ multiple backups? For instance, I’d like to set up a cron job that would backup all my cPanels on the 1st of the month, and also do weekly backups, retaining the two most recently weekly backups. Is that possible?

  • Brian Spotts

    Hmm, I wonder if a solution similar to this one would allow you to create time-stamped backup folders? That way I could retain multiple backups for each account?

    Like instead of having separate folders for each cpanel, all the cpanels would be backed up into a single folder, but it would be stamped with the date (like ‘/cpanel-backup/backup-7-14-20-17’).

    Any idea how I could do that?

  • AdminseHow

    Dropbox retains your older backups automatically. you can use File History feature of Dropbox. read more :

  • Brian Spotts

    Oh thank you for that info! 30 days worth of weekly backups would be fine for my uses too, and I won’t have to go in to dropbox regularly and delete outdated backups. Thanks!

Powered by WordPress