Whitelisting Based Selective Sync In Dropbox - Part II

This is a follow up post to it's Part-I counterpart where I explained both the white and black listing approaches for selective sync in Dropbox. This post intends to describes two different approaches to setting up whitelisting based selective sync on your host machine. These approaches apparently differ on whether you intend to complement whitelisting with an already installed and running instance of Dropbox on your host machine or if you would prefer setting up both the Dropbox instance alongside whitelisting script as a unified solution in a Docker container. Later being the preferred approach for a reason which I will be explaining along the post.

Before we jump onto setting up whitelisting, let's first understand the solution itself.

As already explained in my last post, since whitelisting is not natively supported by Dropbox, the only way to go about implementing such a scheme is via blacklisting. A running Dropbox instance exposes APIs that allow you to add, remove and list files and folders to and from Dropbox's blacklist via command line, like so:

dropbox exclude add sample-file.txt
dropbox exclude remove sample-directory
dropbox exclude list

At a regular interval of time the whitelisting script updates Dropbox's blacklist by blacklisting any files and folders not listed in the whitelist maintained by the user as .dropbox-whitelist.

This solution, however, has a limitation wherein it may Partial Sync, Partial Blacklist data added locally. See my last post on whitelisting based selective sync in Dropbox where I have explained this limitation and it's workarounds in detail.

Another important point to take note of here is that this solution gives you an opportunity to update your whitelist in real time.

You can have a look at the complete script on github.

Solution as a Daemon Process

This approach must be considered only when you wish to setup whitelisting besides the dropbox instance already installed on your host machine.

Clone Repository

Clone github repository on your local machine. This would download the code.

git clone https://github.com/codingkapoor/dropbox-whitelist-selective-sync.git
cd dropbox-whitelist-selective-sync

Create Whitelist

Enlist all the files and folders that you wish to whitelist in .dropbox-whitelist under $HOME/dropbox-whitelist.

mkdir -p $HOME/dropbox-whitelist
cat > $HOME/dropbox-whitelist/.dropbox-whitelist

Copy Script

Copy whitelisting script to $HOME/dropbox-whitelist.

cp ./dropbox-whitelist-selective-sync.sh $HOME/dropbox-whitelist

Copy Systemd Unit File

This file allows you to run the script as Daemon process. Before copying this file to the relevant location you may need to make certain changes to it as per your environment.

Update User, Group to the user and group that your Dropbox instance was ran with and the $HOME and dropbox sync directory location in Exec.

User=<same-user-dropbox-daemon-was-ran-with>
Group=<same-user-dropbox-daemon-was-ran-with>
ExecStart=/bin/bash /<path-to-your-home>/dropbox-whitelist/dropbox-whitelist-selective-sync.sh <dropbox-sync-location>

Updating User and Group properties is a necessary step because if your whitelisting script is ran with a different user, it won't be able to invoke Dropbox's APIs which would result in Dropbox isn't running! issue.

Now copy the unit file to /etc/systemd/system.

cp ./dropbox-whitelist-selective-sync.service /etc/systemd/system

Run Daemon

After necessary modifications to systemd unit file and copying it to relevant location, you can run the script as Daemon process that runs besides your Dropbox instance.

systemctl start dropbox-whitelist-selective-sync.service

Follow Logs

Whitelisting script logs under $HOME/dropbox-whitelist/log.

journald -f -u dropbox-whitelist-selective-sync -e
tail -f $HOME/dropbox-whitelist/log/dropbox-whitelist.log

Here you go! You have successfully setup whitelisting as a daemon process.

Solution as Docker container

There is a fundamental problem with the Daemon approach in that the whitelisting script runs independent of the Dropbox instance on the host machine. The implication being that if the whitelisting script terminates for any reason, the dropbox instance would continue to download and sync newly added data, ignoring whitelist, wasting both bandwidth and space. The container based solution counters this issue by terminating the container and hence the dropbox daemon in case whitelisting script terminates for any reason. This gives you an opportunity to rectify the issue without loosing bandwidth and space on your machine before restarting the docker container.

Build Docker Image

docker build -t codingkapoor/dropbox https://github.com/codingkapoor/dropbox-whitelist-selective-sync.git

Create Whitelist

Enlist all the files and folders that you wish to whitelist in .dropbox-whitelist under $HOME/dropbox-whitelist.

mkdir -p $HOME/dropbox-whitelist
cat > $HOME/dropbox-whitelist/.dropbox-whitelist

Run Docker Container

The container will locate the whitelist from under $HOME/dropbox-whitelist. You can always specify a different location on your host machine with the container based approach if you in case decide to launch multiple such instances as explained in one of mine earlier blog post on configuring multiple dropbox instances on a single host.

docker run -d --name=dropbox --restart=always --volume=$DROPBOX_SYNC_DIR:/dbox/Dropbox --volume=$HOME/dropbox-whitelist:/root/dropbox-whitelist codingkapoor/dropbox

Link Dropbox Account

Check the logs of the container to get a URL to link your Dropbox account.

docker logs -f dropbox

Copy and paste the registration link from container logs in a browser to register your dropbox account to the dropbox instance running inside your container.

That's it! You have successfully setup whitelisting backed Dropbox instance as a Docker container.

Show Comments