Sipsmi's Blog

Techno ramblings of a cynical engineer

Backup to dropbox with duplicity

leave a comment »

Pre-conditions:

  • Assume you have installed duplicity and have a dopbox account?

So I want to backup some essential stuff from my cloud server.  Dropbox pro costs next to nothing for storage and it seems that duplicity has a dropbox backend which can use the dropbox API.

First things first make sure you have the dropbox API python libraries – you can get help here:

https://blog.fite.cat/2014/05/full-backup-with-duplicity-and-dropbox/

Note that the patch is needed ( http://bazaar.launchpad.net/~ed.so/duplicity/fix.dpbx/revision/965#duplicity/backends/dpbxbackend.py ) if you are using Ubuntu 14LTS – the file can be found in /usr/lib/python2.7/dist-packages/duplicity/backends on Ubunutu.

Now you need to get an authorisation token to use this with dropbox – in order to do this just run the code and you will be prompted with a URL to do to register an application under  /Apps/duplicity

duplicity /etc dpbx:///test

Follow the URL and authorise the account then press return.  This will save OAuth token to .dropbox.token….  copy this to appropriate home directory if using another account to backup.

Points to remember, every time you use a new base folder you have to create it (use the dropbox web interface), so for that previous one to work I would have to create test under Apps/duplicity

Now I have bundled this all into a script which takes a number of directories and places & backs them up daily (cron invocation) to a number of named folders.

 

#!/bin/bash
# set destination (other backends are avaialble 🙂
dest=dpbx:///vol1
# Setting the pass phrase to encrypt the backup files.
export PASSPHRASE='<somethign complex>'
#
# declare the directories to be backed up and where to stick-em
#
declare -A bkupArr
bkupArr=( 
     [/var/www/edoc/upload]=edocupload,
     [/home/data]=data 
)
#
# do the backup
#
for bkup in ${!bkupArr[@]}
do
   bkupDest=${bkupArr[$bkup]}
   echo "Backing up $bkup to " $dest/$bkupDest 
   # doing a monthly full backup (1M)
   duplicity --full-if-older-than 1M $bkup $dest/$bkupDest
   # clean backup space 
   duplicity remove-older-than 3M --force $dest/$bkupDest
done
# Unsetting the confidential variables so they are
# gone for sure.
unset PASSPHRASE
# quit
exit 0

 

 

Disclaimer: This code is from a hardware engineer turned hacker, it most likely aint pretty, it most likely can be done better but …. it works.

 

Advertisements

Written by sipsmi

February 18, 2016 at 4:05 pm

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s