how to have normal and shared dropbox folders in sync with owncloud.
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:
mkdir -p ~/bin ln -s ~/.dropbox/dropbox.py ~/bin/dropbox.py
We then create the file ~/bin/start_dropbox.sh with the following content:
#!/bin/bash SCRIPT_NAME=`basename $0` if ps ax | grep -v grep | grep -v $SCRIPT_NAME | grep dropbox then echo "Dropbox is running" else echo "Dropbox is not running. Restarting" ~/bin/dropbox.py start fi
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
The following lines should be appended to the end of the file:
@reboot ~/.dropbox-dist/dropboxd */5 * * * * ~/bin/start_dropbox.sh
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:
Research |-- Editorials |-- Explorations |-- Papers |-- Publications |-- Theses
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.
# if the ownCloud username is different to the GNU/Linux username, substitute `whoami` with the ownCloud username. ln -s ~/Dropbox/Research ~/data/`whoami`/files/Research
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:
#!/bin/bash /usr/bin/mysql -h yourmysqlhost -u yourdbuser -pyourpasswordheredontputaspacebeforeit databasename -Bse "DELETE from oc_storages; DELETE FROM oc_filecache"
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
. The following lines should be appended to the end of the file:
* 3 * * * ~/bin/clean_owncloud.sh
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”.
We receive the usual Dropbox e-mail with the shared folder invitation, that has to be accepted.
Dropbox website has to be accessed. The folder will be in the root directory of Dropbox.
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.
The folder will be synced on the ownCloud server through Dropbox command line. The folder will immediately go in the ownCloud-handled folders.
ownCloud will recognize the new folder in a matter of minutes (a couple of minutes normally).
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.
I do not use a commenting system anymore, but I would be glad to read your comments and feedback. Feel free to contact me.