Skip to content

Instantly share code, notes, and snippets.

@fjebaker
Last active March 22, 2024 22:09
Show Gist options
  • Save fjebaker/22983ce6db570def2980af8d7235bba2 to your computer and use it in GitHub Desktop.
Save fjebaker/22983ce6db570def2980af8d7235bba2 to your computer and use it in GitHub Desktop.
How to setup a private Zotero sync using WebDAV and Docker.

Zotero Sync with WebDAV and Docker

Zotero is another tool for keeping track of research papers, except Zotero does much more than that: the open source software ships with a browser extension which allows you to add almost anything (papers, book, videos, wikipedia pages) to your library with a single click, keep notes and additional resources close at hand, and export citations in a whole mass of different formats.

In addition to all that, Zotero also comes with a cloud storage sync, so you can back up all of your library and sync it on other machines.

Zotero provides a WebDAV client so that you can host your own, however this isn't particuarly well documented to date.

  • Requisites:

You'll need Docker and a Zotero login (file sync is prevented without a login, so you can create a throw away one if so desired).

Update 2021

The bytemark image suggested is broken if built from source, see this issue.

The solution is to edit to the dockerfile to specify the httpd version -- which should be

FROM httpd:2.4.37-alpine

The Docker Image

I spent quite a bit of time trying to find an effective WebDAV server to use, and settled on the Apache WebDAV docker container by bytemark. The container is just shy of 100 MB on DockerHub, but as I will be running this on a raspberry pi, cloned the repository and built the image myself for ARM.

Using the image is straight forward:

docker run -d \
     --rm \
     --name zoterosync \
     -v /path/to/storage:/var/lib/dav \
     -e AUTH_TYPE=Digest \
     -e USERNAME=alice \
     -e PASSWORD=white_rabbit \
     -p 9800:80 \
     -e LOCATION=/zotero/ \
     bytemark/webdav

Note it is my personal flavour to always use --rm, as I really like having throwaway containers and thus all state stored on my machine.

This is a HTTP WebDAV server with a simple Digest-type authentication, though the image does support HTTPs, I just didn't feel like messing around with self-signed X.509s.

We set the LOCATION environment variable, which is the entrypoint-URL of the server, to /zotero/ (both slashes are essential). The sync client has this route hardcoded, so we don't have a lot of options.

The rest is all pretty straight forward. On my raspberry pi, I have an external storage mounted, which I use to backup (gigabytes) of Zotero storage. I wrapped the above command in a linux service which I'll include for completeness:

[Unit]
Description=Docker Apache WebDAV Service
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=[ABOVE_COMMAND]
ExecStop=/usr/bin/docker stop zoterosync
TimoutStartSec=0

[Install]
WantedBy=multi-user.target

I've written notes on using Docker containers as services for more information.

Configuring Zotero

Launch the client and navigate to Preferences/Sync, where you will have to sign in with your Zotero login.

After this, uncheck Sync attachment files in group libraries using Zotero storage, and from the drop down above, select WebDAV.

Here you enter the address of your WebDAV server, e.g. locahost:9800, and the login details for WebDAV. Don't forget to change the protocol to HTTP.

Click verify server, and with a bit of luck, it will all just work. Close preferences, and use the sync button top right to backup all your library and feeds onto your WebDAV server.

Troubleshooting

So you're here are you. Well, there's not much I can do to help, but there's a few issues I encountered:

  • my client connected to WebDAV successfully, but on using the sync button, would send an OPTIONS request to the server and then silently fail. I was able to resolve this by syncing to the Zotero cloud and then switching back to WebDAV (I think some caching is going on).
  • another issue can be the route; it's really essential to set the LOCATION to /zotero/ with both slashes.

Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment