A robust bash script for Unraid users to perform a one-way sync from Dropbox to a Nextcloud AIO instance. This script includes automated versioning (archiving), permission management for Nextcloud AIO, and native Unraid GUI notifications.
- One-Way Sync: Keeps your Nextcloud updated with Dropbox without deleting local files.
- Automated Versioning: Uses rclone's
--backup-dirto move modified files to a dated archive instead of overwriting them. - AIO Compatibility: Automatically handles the
UID 33(www-data) permissions required by Nextcloud AIO. - Instant UI Refresh: Triggers an
occ files:scanso files appear in Nextcloud immediately. - Native Notifications: Sends status alerts directly to the Unraid dashboard.
- Unraid OS with the User Scripts plugin installed.
- rclone installed via the Unraid App Store (rclone plugin).
- Nextcloud AIO (All-in-One) Docker container running.
By default, Unraid stores rclone configs in RAM, which vanish on reboot. Follow these steps to make your Dropbox connection persistent.
-
Open the Unraid Terminal.
-
Run the configuration wizard:
rclone config
If you've already moved the config file off RAM and into persistent storage, you can still run config for the specific config file:
rclone --config "/boot/config/plugins/rclone/rclone.conf" config -
Create a new remote named
dropbox-personal(or your preferred name) and follow the OAuth login steps. -
Crucial: Move the config file to your flash drive so it survives reboots:
mkdir -p /boot/config/plugins/rclone/
mv /root/.config/rclone/rclone.conf /boot/config/plugins/rclone/rclone.conf
- Go to Settings > User Scripts on Unraid.
- Click Add New Script and name it
Sync_Dropbox_Personal. - Paste the following code:
#!/bin/bash
# 1. Variables
NC_USER="admin"
CONFIG_PATH="/boot/config/plugins/rclone/rclone.conf"
SOURCE="dropbox-personal:/"
DESTINATION="/mnt/user/nextcloud/$NC_USER/files/Dropbox"
TIMESTAMP=$(date +%Y-%m-%d)
BACKUP_DIR="/mnt/user/nextcloud/$NC_USER/files/Dropbox_Archive/$TIMESTAMP"
# 2. Check if Config exists
if [ ! -f "$CONFIG_PATH" ]; then
/usr/local/emhttp/plugins/dynamix/scripts/notify -s "Dropbox Sync FAILED" -d "Rclone config not found at $CONFIG_PATH" -i "alert"
exit 1
fi
# 3. Notification: Starting
/usr/local/emhttp/plugins/dynamix/scripts/notify -s "Dropbox Sync" -d "Starting one-way copy to Nextcloud..."
# 4. Perform the Copy with Versioning
echo "Starting One-Way Copy with Versioning..."
rclone --config "$CONFIG_PATH" copy "$SOURCE" "$DESTINATION" \
--backup-dir "$BACKUP_DIR" \
--update \
--verbose
# 5. Permissions fix
# Note: Using 33:33 for Nextcloud AIO compatibility (www-data internal user)
chown -R 33:33 "/mnt/user/nextcloud/$NC_USER/files/Dropbox"
chown -R 33:33 "/mnt/user/nextcloud/$NC_USER/files/Dropbox_Archive"
# 6. Refresh Nextcloud AIO
echo "Refreshing Nextcloud Database..."
docker exec --user www-data nextcloud-aio-nextcloud php /var/www/html/occ files:scan --path="/$NC_USER/files/Dropbox"
docker exec --user www-data nextcloud-aio-nextcloud php /var/www/html/occ files:scan --path="/$NC_USER/files/Dropbox_Archive"
# 7. Notification: Finished
/usr/local/emhttp/plugins/dynamix/scripts/notify -s "Dropbox Sync" -d "One-way copy and Nextcloud scan completed successfully @ $(date +%H:%M:%S)."
echo "Sync and Versioning Complete at $(date)"
Ensure your Nextcloud share is correctly mapped. The script assumes your data is located at:
/mnt/user/nextcloud/[user]/files/
If you have multiple Dropbox accounts, simply create a second script, change the SOURCE name to your second rclone remote, and update the DESTINATION to a different folder (e.g., /Dropbox_Work).
Make sure to create both remotes in rclone together, then move the configuration file to persistent storage as described above in 1.4.
In the User Scripts dashboard, set the schedule for your script:
- Daily: Runs once every night.
- Custom: Use
0 */6 * * *to run every 6 hours.
- Scan shows 0 files: Ensure the
NC_USERvariable matches your Nextcloud login exactly (case-sensitive). - Permission Denied: Ensure your Nextcloud share is accessible and the script is running as
root(default for User Scripts). - Container Name: If your Nextcloud AIO container is not named
nextcloud-aio-nextcloud, update thedocker execline in the script to match your container name.
Created with the help of Gemini - Capable and genuinely helpful AI thought partner.