Last Updated: February 25, 2016
·
1.162K
· sevcsik

Using Dropbox for server backup

Dropbox is a surprisingly cheap and efficient way to manage your (moderate) backup needs. Dropbox's wonderful sync logic and revision control makes regular backup a piace of cake, because:

  • It only syncs when the file is actually changed - regular backups won't cause vain network traffic
  • You don't have to store older versions and rotate them - Dropbox takes care of version control, so you're safe to overwrite the old backup
  • Basically you just write (or link) a file and forget about it

My example is based on this fine article, with a few changes.

First, set up a user account for Dropbox, so you don't need to give any unnecessary privileges to the proprietary dropboxd. We'll use /var/dropbox for the sync directory.

# useradd dropbox -d /var/dropbox
# mkdir /var/dropbox
# chown dropbox /var/dropbox

Now, download the helper script into the home directory (packages would attempt to pull GUI dependencies), and install the daemon.

# su dropbox
$ cd
$ wget https://www.dropbox.com/download?dl=packages/dropbox.py -O dropbox.py
$ chmod +x dropbox.py
$ ./dropbox.py start -i

Unfortunately dropbox.py won't output the authentication URL, so we need to stop and start dropboxd directly, to get it.

$ ./dropbox.py stop
$ .dropbox-dist/dropboxd

After the setup, this will create a Dropbox folder, and we're set up. To avoid this hassle in the future, I suggest using James Coyle's wonderful init script.

Assuming you're using different users for different services, and you want to keep the backup for those users as well, add each user to the dropbox group, and add group permissions to the sync folder:

$ exit
# usermod -aG dropbox my-daemon-user
# su dropbox
$ chmod g+rwx Dropbox

This way every user can create it's own folder, which cannot be tampered with by others (depending on your umask). Be sure to add group read permissions to the files, otherwise dropboxd won't be able to sync them.

After these, all you have to do is to set up your cron jobs to do the backups. Here's an examlple of backing up my Trac database every hour:

# su trac
$ mkdir /var/dropbox/Dropbox/trac
$ crontab -e

And the crontab line:

0 * * * * * pg_dump trac > /var/dropbox/Dropbox/trac/trac_dump.pgsql

And that's it! Every one hour, my database get's backed up to Dropbox, but only if there has been a change. Sweet!