How to Include Folders in Dropbox Selective Sync via Command Line on Linux


2 views

Dropbox's selective sync feature allows users to choose which folders sync to their local machine. While the GUI makes this straightforward, Linux users often need command-line solutions for server environments or automation.

Curiously, while dropbox exclude exists in the CLI, there's no direct include counterpart. This creates challenges when you need to re-add previously excluded folders programmatically.


# Current available commands (as of Dropbox v178.4.6190)
dropbox status
dropbox exclude add|remove|list [PATH]
dropbox lansync y|n

To include folders, you need to remove them from the exclusion list. Here's how:


# List currently excluded folders
dropbox exclude list

# Remove a folder from exclusion (effectively including it)
dropbox exclude remove ~/Dropbox/Projects/SecretProject

For scripting purposes, you can parse the exclusion list and selectively re-include folders:


#!/bin/bash

TARGET_FOLDER="$HOME/Dropbox/ImportantFolder"

# Check if folder is excluded
if dropbox exclude list | grep -q "$TARGET_FOLDER"; then
    echo "Re-including $TARGET_FOLDER"
    dropbox exclude remove "$TARGET_FOLDER"
else
    echo "Folder not excluded or already included"
fi

Dropbox stores sync preferences in a SQLite database. While not officially supported, you can modify it directly:


# Location of the config database
DB_PATH="$HOME/.dropbox/instance1/config.dbx"

# Query excluded folders (requires sqlite3)
sqlite3 "$DB_PATH" "SELECT value FROM config WHERE key='exclude_list'"

For those experiencing missing icons (mentioned in the original question), ensure you have the proper indicator dependencies:


# For Ubuntu/Debian systems
sudo apt install libappindicator1

Dropbox's selective sync feature allows users to choose which folders sync to their local machine, conserving disk space. While the official CLI provides an exclude command, there's no direct include counterpart. Here's how to work around this limitation.

Before proceeding, ensure:

  • Dropbox is installed and running (dropbox status)
  • You have write permissions for ~/.dropbox folder
  • Python is available (for JSON manipulation)

Selective sync settings are stored in ~/.dropbox/info.json. To include folders, we need to:

  1. Modify the JSON configuration
  2. Restart Dropbox

First, check current exclusions:

cat ~/.dropbox/info.json | python -m json.tool

To include a previously excluded folder:

#!/bin/bash
# include_folder.sh - Adds folder back to Dropbox sync

FOLDER_PATH="$1"
CONFIG_FILE="$HOME/.dropbox/info.json"

if [ -z "$FOLDER_PATH" ]; then
    echo "Usage: $0 /path/to/folder"
    exit 1
fi

# Create backup
cp "$CONFIG_FILE" "${CONFIG_FILE}.bak"

python -c "
import json, sys
with open('$CONFIG_FILE') as f:
    data = json.load(f)
if 'business' in data:
    data['business']['excluded'] = [x for x in data['business']['excluded'] if x != '$FOLDER_PATH']
else:
    data['personal']['excluded'] = [x for x in data['personal']['excluded'] if x != '$FOLDER_PATH']
with open('$CONFIG_FILE', 'w') as f:
    json.dump(data, f, indent=4)
"

dropbox stop
dropbox start

After running the script:

  1. Check folder appears in Dropbox UI
  2. Verify sync status: dropbox filestatus "$FOLDER_PATH"
  3. Monitor sync progress: dropbox status

For those uncomfortable with direct JSON editing:

Method 1: Use Dropbox CLI's exclude command to reset all exclusions

# First get all excluded folders
EXCLUDED=$(python -c "import json; d=json.load(open('$HOME/.dropbox/info.json')); print(' '.join(d['personal']['excluded']))")

# Re-exclude all except the one you want to include
for folder in $EXCLUDED; do
    if [ "$folder" != "/path/to/include" ]; then
        dropbox exclude add "$folder"
    fi
done