Jul 9, 2013

How to have normal and shared Dropbox folders in sync with ownCloud.

Owncloud, the Open Source Dropbox alternative

In a previous post about ownCloud, I mentioned that I found a way to employ ownCloud while keeping it synced to a Dropbox folder, as some university colleagues use Dropbox to perform collaborative tasks. OwnCloud external storage support for Dropbox is just limited. It often does not work and it is not reactive, especially when using Dropbox shared folders. I also wanted to use ownCloud while not forcing colleagues to abandon their Dropbox and keep doing collaborative work with them. There was the need to let them transparently use Dropbox and make them act as if I had Dropbox. This post describes how I did it.

First of all, a disclaimer: what it is described below is a simple, yet dirty hack. The reader is advised to not rely on it and to not expect 100% reliability.


This set of instructions has the following assumptions:

  • ownCloud v5.0.x is being employed
  • ownCloud is installed either on a VPS or on a very permissive web hosting system (e.g., Webfaction)
  • SSH access is available in the hosting system
  • Crontab is available in the hosting system
  • The command-line version of Dropbox is installed and running from the user’s home folder

Keep Dropbox up and running

First of all, we make sure that Dropbox is running and keeps running.
For simplicity, we symlink the Dropbox executable inside a ~/bin folder (in our home directory).

The following should be run in a remote terminal connection:

We then create the file ~/bin/start_dropbox.sh with the following content:

The script has to be made executable with chmod +x ~/bin/start_dropbox.sh.
It should be run each X minutes (say, 5) to make sure Dropbox never crashes. We issue the command crontab -e.

The following lines should be appended to the end of the file:

The first line makes sure that Dropbox gets started at each system reboot. The second line calls the previously created file each 5 minutes.
The script should already perform the work of the first line, in the worst case 5 minutes after the system reboots. As it does not hurt, it may be safely kept there.

Physically link Dropbox and ownCloud

As Dropbox is up and running, it is time to keep a folder in sync with ownCloud.
In my case, the ~/Dropbox folder only contains the directory I want to keep in sync. “Unwanted” directories should be excluded from Dropbox sync.

Suppose our ownCloud data folder is ~/data/yourusername. Suppose also that we have a Dropbox folder, Research, organized as follows:

The Research/Publications folder mostly contains Dropbox shared folders. There is also the need to sometimes share other Research sub-folders with Dropbox users.
Therefore, there is the need to have the whole Research folder synchronized between Dropbox and ownCloud. This is achieved using symlinks.

Keep ownCloud in sync with Dropox file changes

At this point, ownCloud’s data folder physically contains the Dropbox folder to be kept in sync. Although the folders will be kept in sync at the files level, it is still not sufficient for ownCloud to sync the newly created or changed files through the sync-clients. We need to give ownCloud a little help.

We should make sure that ownCloud background jobs are correctly executed. As the AJAX cronjob is the least reliable, classic Cron and Webcron are preferred. I am using the Webcron option with Easycron setup each 5 minutes, because manually calling cron.php from the command line has often given me errors in the past.

Another method would be to regularly delete ownCloud cache in order to trigger a rebuild of the filesystem. While this method works for me, it has drawbacks. One of them is that it may delete ownCloud internal shares.

I do not encourage the usage of what follows. However, it is working fine for me. It has been written with the assumption that ownCloud has been installed with MySQL support.

We create the file ~/bin/clean_owncloud.sh with this content:

The script must be made executable with chmod +x ~/bin/clean_owncloud.sh.
This script should be regularly called (let’s say, each night at 03:00). We issue the command crontab -e. The following lines should be appended to the end of the file:

This is everything, which is needed for the synchronization to work. It should ensure an often flawless synchronization with Dropbox and ownCloud.

OwnCloud is a young project. Sometimes there are bugs in the server side. Sometimes there are bugs in the client and the index has to be reset locally.
Sometimes, it may be necessary to restart Apache and PHP (if run separately) in order to make changes appear almost immediately.
However, I am very satisfied with the results. In the following section, we will see how the flow between my colleagues and me works.

How the flow works

Suppose a colleague wants to share the folder “Analysis of Open Access Journals”.

  1. We receive the usual Dropbox e-mail with the shared folder invitation, that has to be accepted.
  2. Dropbox website has to be accessed. The folder will be in the root directory of Dropbox.
  3. The “Analysis of Open Access Journals” folder has to be moved inside the synced folder. For example, the final path would be Research/Publications/Analysis of Open Access Journals. This
    can be done in Dropbox website, via drag and drop.
  4. The folder will be synced on the ownCloud server through Dropbox command line. The folder will immediately go in the ownCloud-handled folders.
  5. ownCloud will recognize the new folder in a matter of minutes (a couple of minutes normally).
  6. ownCloud sync-client will see the new folder and synchronize it on the local computer.

Each subsequent file operation will automatically be synced in Dropbox, as well. Unfortunately, this process is not as immediate as Dropbox. However, the hacks described in this tutorial are exactly meant to speed up the process as fast as possible. Usually, it is a matter of 5 minutes to have a change propagated.

To share a folder with a Dropbox user, it is necessary to create the folder inside the one which is synchronized. When it gets synchronized to Dropbox, the folder has to be shared from Dropbox website.

written by dgraziotin

Dr. Daniel Graziotin received his PhD in computer science, software engineering at the Free University of Bozen-Bolzano, Italy. His research interests include human aspects in empirical software engineering with psychological measurements, Web engineering, and open science. He researches, publishes, and reviews for venues in software engineering, human-computer interaction, and psychology. Daniel is the founder of the psychoempirical software engineering discipline and guidelines. He is associate editor at the Journal of Open Research Software, academic editor at the Research Ideas and Outcomes (RIO) journal, and academic editor at the Open Communications in Computer Science journal. He is the local coordinator of the Italian Open science local group for the Open Knowledge Foundation. He is a member of ACM, SIGSOFT, and IEEE.


Leave a comment