<coded>


Sync data to Dropbox from your SSH terminal

May 18, 2022

With this method you can upload/sync your local backups to your Dropbox instead of downloading it to your home drive.

Requirements

1. Create Dropbox App

First step is to create a Dropbox App. Go to Developer Settings and do this steps:

Go to Permissions tab and set the following checkboxes:

Go back to Settings tab. For the Uploader you will need App key, App secret and access token now.

2. Download Dropbox-Uploader from Github

Then we just get the Shell script from Github in our /home/user directory:

curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh

3. Set script permissions and script settings

Now set script permissions to +x and execute the script:

chmod +x dropbox_uploader.sh
./dropbox_uploader.sh

You will be guided through a setup wizard now, to access your Dropbox. Fill out the required data to establish the Dropbox connection.

4. Usage and commands

Shell script comes with a lot of commands, you can find all of the on the Github page. We only use upload for now:

upload <LOCAL_FILE/DIR ...> <REMOTE_FILE/DIR>

5. Combine Dropbox-Uploader with our backup script

In reference to: Make your own backup script in Debian we can simply add 2 more lines to our backup script in order to sync it to our Dropbox now:

#!/bin/sh
mkdir /home/coded/backups/`date +"%Y%m%d"`
zip -r /home/coded/backups/`date +"%Y%m%d"`/apache-backup.zip /etc/apache2/sites-available
zip -r /home/coded/backups/`date +"%Y%m%d"`/nextcloud-backup.zip /var/www/html/nextcloud
mysqldump --single-transaction -h localhost -u YOURUSER -pYOURPASSWORD nextcloud > /home/coded/backups/`date +"%Y%m%d"`/mysql-backup.sql
./dropbox_uploader.sh upload /home/coded/backups/`date +"%Y%m%d"` /dropboxBackups
rm -r /home/coded/backups/`date +"%Y%m%d"`

With rm -r we remove the folder on our first machine again to keep it clean.

Did you find this useful? Please rate this post: