This github page, https://github.com/andreafabrizi/Dropbox-Uploader, has the dropbox-uploader tool which I use to backup content from servers (Linux, Mac, etc) without having to sync my Dropbox content to the local disk on your server.
Before using the uploader, get an API key dropbox, Here is how you do that.
Note that there are 2 levels of access each API gets (which you configure):
- Full access – allows the API to access your entire Dropbox (so if it fell into wrong hands it could access/write/delete into anything – even go as far as delete everything). The benefit is that a user can specify which directory in their Dropbox file system to backup files to.
- Application access – This access limits the API to only the /Apps/<appname> directory (if the /Apps/<appname> directory is missing it will be created on the root of your Dropbox file system). So you can only backup content to /Apps/<appname>/. Within that directory the API has full control (well the access can be fine tuned)
For backup purposes just use the application level access, there is no reason for it to potentially have access to all of your Dropbox data.
More info on these access levels and Oauth authentication is here, https://www.dropbox.com/lp/developers/reference/oauth-guide
Steps by example:
First install dropbox_uploader.sh to any location of your choosing in your filesystem.
Now create a db.conf file. If you run dropbox_uploader.sh without the -f option, it will prompt you for your OAUTH KEY and create the conf file in its default location. I prefer putting it in a custom location.
echo "OAUTH_ACCESS_TOKEN=gvi4325ffFAKEKEYwadfasd-i234asdfa" > ~/backups/db.conf
Then if I want to copy a file called yourfile.txt, first I delete it from the destination. I do this to avoid possible time consuming hash-checks, because if the file already exists at the destination, this script does a hash check.
./dropbox_uploader.sh -f ~/backups/db.conf delete /yourfile.txt
Then I upload the file, by specifyin the source and destination location. Note the destination location must start with a forward slash. If your key have full access it will go to Dropbox:yourlocation. If your key has app access it will go to Dropbox:/Apps/appname/yourlocation. If you are unsure if the directories, exist, don’t worry the API creates the needed directories (even if they are a few nested ones).
./dropbox_uploader.sh -f ~/backups/db.conf upload ~/yourfile.txt /yourfile.txt
I use this tool to backup servers (data compressed with tar+xz => good high compression) to dropbox. In my backup script which is called by cron daily or however often, I do all of the above steps. I create the db.conf everytime, that way I can see all of the settings and commands from the backup script and don’t have to rummage thru my filesystem for my config file.
DROPBOX_OAUTH_TOKEN='gvi4325ffFAKEKEYwadfasd-i234asdfas' # hardcode my key into backup script (you can skip this) echo "OAUTH_ACCESS_TOKEN=$DROPBOX_OAUTH_TOKEN" > ~/backups/db.conf # recreate this file each time backup is run (optional) DAYOFWEEK=$(date +%w%a) # depending on day of week 0Sun, 1Mon, 2Tue, ... 6Sat (useful to only have 7 backups) SOURCEFILE="~/backups/somebackup.tar.xz" # specify file to copy TARGETFILE="/backups/somebackup-$DAYOFWEEK.tar.xz" # ** see note 1 beloww ** DBUP="./dropbox_uploader.sh -f ~/backups/db.conf" # this part is repeated alot so made it into a variable $DBUP delete $REMOTEFILE # ** see note 2 below ** $DBUP upload "$F.xz" "$REMOTEFILE" # upload source file to target location # note 1: TARGETFILE specifies dump location. it should start with a forward slash /. With full access privs this dumps to Dropbox:/backups/somebackup-$DAYOFWEEK.tar.xz. With App access privs this dumps to Dropbox:/Apps/appname/backups/somebackup-$DAYOFWEEK.tar.xz # note 2: first lets we delete the file that might be there (saves time so we dont have to hashcheck - this uploader compares hashes). Also first few delete operation will error as nothing exists on the target yet, you can ignore that