Combining ownCloud and syncthing

syncloudOwnCloud is a nice cloud solution which is based on free software. It allows companies and users to run their own cloud services thereby not loosing the control on their data. Every day this gets more and more important and you loose control if you use commercial cloud services such as Google, Microsoft, or Amazon.

OwnCloud allows to synchronize contacts, calendars, email, files, and has many more features. Unfortunately, there is no real-time background synchronization of folders, yet.

Syncthing is a folder sharing system which allows real-time synchronization of shared folders between your devices and others. Basically it works similar to Dropbox, but again, syncthing is free software, which Dropbox is not. Thus you control to who and where your data goes, which in fact is not known for Dropbox.

Combining both, ownCloud and syncthing actually adds background folder synchronization to the ownCloud features. Please also read update at the end of this article!

Preparation

Let’s assume that you have a standard ownCloud installation already set up. Thus, you have a web server running PHP. In my case this is a FreeBSD 10.1 running Apache 2.4 with PHP 5.6. The ownCloud installation resides in /usr/local/www/apache24/owncloud and the data directory is outside the program path in /usr/local/www/apache24/owncloud_data as suggested by the documentation.

owncloudOwnCloud as well as syncthing access the file systems, thus we have to get the file system permissions right. OwnCloud runs as web application under the web server which typically runs as the user www. We will start syncthing under your local user on the system.1 Let’s assume the local user is john.

Add a new group to /etc/group and add www and john as group members:

owncloud:*:200:john,www

Restart the web server and recursively change the group of the ownCloud data directory and its file mode:

$ sudo chgrp -R owncloud owncloud_data
$ sudo chmod 770 owncloud_data

Login to your ownCloud and create a directory. It will be used as sync-directory. Let’s name it “syncthing”.

Running Syncthing

syncthingNow start a screen session by simply running screen. Install it if you don’t have it in your system. Run syncthing within the screen session. Now we have to add a synchronization folder to syncthing. Syncthing has a config directory which is in ~/.config/syncthing but unfortunately it is a somewhat confusing XML file. Thus, the better way is to use the web frontend which is built into syncthing on port 8384. Since syncthing runs on your ownCloud server, use ssh port forwarding to connect to the web config console. Logout from the terminal of your server and login again with appropriate port forwarding enabled:

$ ssh -L 8384:localhost:8384 yourserver.foobar.com

Now locally run the browser of your choice2 and enter the URL http://localhost:8384/ .

The syncthing config front end shall open. On the left side now add a folder according to the syncthing documentation. Import is that you set the folder path to the path of the sync-directory within the ownCloud data directory. In our example this is /usr/local/www/apache24/owncloud_data/eagle/files/syncthing.

Follow the syncthing documentation to add your smart phone to your syncthing server and vice versa, and add the folder to the syncthing app on your phone as well.

That’s all folks!

Drawback

OwnCloud is a multi-user environment while the syncthing client is only a single user tool. This makes it a little bit difficult if you have several users in your ownCloud and you want to have this syncthing feature for all of them. But this is another story ­čśë

Have phun using syncthing and ownCloud together ­čÖé


Important Update 2016/01/03

  1. I explained about file permissions above. Unfortunately, I forgot to write about the umask. Before running syncthing you have to set the umask to 002. Execute `umask 002 && synchting`.
  2. Owncloud stores the files within a database. A change in the file system directly on the server (e.g. by syncthing) without using the ownCloud frontend will lead to an inconsistency (see this issue on Github). To fix such inconsistencies you have to run the ownCloud console script: `occ files:scan john`. The best workaround currently is to put this into the crontab of the www user. run `sudo crontab -u www -e` and add the following line which resyncs every 10 minutes:

0,10,20,30,40,50 * * * * /usr/local/bin/php /usr/local/www/apache24/owncloud/occ files:scan eagle >/dev/null


Update 2017/06/27

Nice article about secure Dropbox-alternatives: ┬╗Three Dropbox Competitors for Secure Storage┬ź.


 

  1. Of course, this shall never be root.
  2. On the system from which you are doing the configuration, not on the server.