Moving out of the Cloud into… my ownCloud

I’ve been using Google Calendar and Google Contacts for a long time, and never felt confortable with it. Externalisation is like the dark side of the force: faster, easier, but in the end not more powerful. So recently when I had some free time, I thought it was time to install ownCloud and leave Google behind. And integrate my calendar with Mutt, while I was at it.

This page was written a long time ago, probably before 2015. I think these days it is better to move to NextCloud rather than ownCloud. I intend to migrate at some point, mostly because OwnCloud is being displaced by NextCloud in Debian.

Moving into ownCloud

ownCloud is pretty cool: it’s got a Web-based calendar that’s similar in functionality to GoogleCalendar, a Contacts application that works really well, a file sharing service, and contrary to Google and Android it all relies on open standards such as CalDAV and CardDAV. This page recounts some of the steps I took to migrate from Google to my ownCloud, as it was not all smooth.

First, I created a new LXC with a SID distribution: ownCloud being all PHP and rather complex, I prefer to have it in a separate container, and on top of that ownCloud is actually available as a Debian package. I picked the package owncloud-sqlite, as I don’t fancy setting up a database and I don’t expect to host many users. I also added a DNS entry to make my cloud accessible, and did some pretty messy things on my front Apache to redirect a virtual host to an LXC.

To import data, and later to interface Mutt with ownCloud’s calendar, I use cadaver, a DAV command line client. It can be configured through a .netrc file so it can access your DAV locations without typing passwords, which is rather convienent:

    $ cat ~/.netrc
    machine cloud.rutschle.net
    login yves
    password helloworld

Then, I retrieved my Google Calendar and Contacts, which Google nicely provides as ICF and VCF files.

  • For Calendar, in ‘Parameters’, ‘Calendars’, select the calendar you want to retrieve. In the calendar page, get the URL for the ICAL export.
  • For Contacts, in ‘More’, ‘Export’, retrieve a vCard file.

One problem I had is that I ended up with my calendar in one ICS file and contacts in one VCF file, but couldn’t import these directly in ownCloud. I found I needed to split the files in unary calendar entries and unary contacts, then upload them to ownCloud’s DAV interface using So I wrote two script: ics_split, which turns one ICS file into a bunch of individual events, and vcf_split, which turns one VCF file into a bunch of individual contacts. Then you upload all these files to the appropriate DAV locations using cadaver:

    $ ics_split calendar.ics
    $ vcf_split contacts.vcf
    $ cadaver http://cloud.rutschle.net/owncloud/remote.php/caldav/calendars/yves/personal
    cadaver> mput *.ics
    cadaver> exit
    $ cadaver http://cloud.rutschle.net/owncloud/remote.php/carddav/addressbooks/yves/contacts/
    cadaver> mput *.vcf
    cadaver> exit

Depending on how many contacts and calendar entries you have, this may take… a long time. The files are tiny but each file takes a fraction of a second, so the full import can take a good 20 minutes.

In order to get e-mails and notifications, I installed ssmtp in the LXC and added a crontab:

    */15 * * * * php -f /usr/share/owncloud/cron.php

At this point, you have a Web interface that’s functionally equivalent to Google Calendar and Contacts.

News

While we’re at it, we can also move out of Feedly: export the OPML file (by clicking on your account name at the bottom left corner, the scrolling at the bottom of the list of feeds, “Save as OPM”), install the News app (basically clone their git in /usr/share/owncloud/apps and enable the app in the admin panel of ownCloud), then import the OPML. Done (well, give it some time to then download everything). The News app is very similar to Feedly’s interface, it even imports all the same folder hierarchy.

At that point, I’ve replaced all external services I used to use. I am pretty happy. Backups ======= I run this in a crontab, then backup the dump directory in my usual backup system. #! /bin/sh cd /var/lib/owncloud BACKUP_DIR=/tmp/owncloud.bak mkdir -p $BACKUP_DIR sqlite3 data/owncloud.db .dump > $BACKUP_DIR/owncloud-sqlbkp.bak rsync -a /var/lib/owncloud $BACKUP_DIR/owncloud-dir cp /etc/owncloud/config.php $BACKUP_DIR/ At some point I’ll have to test that this actually let me rebuild a working owncloud… Processing calendar invitations with Mutt ========================================= Install ics_tools for seamless integration of Mutt, Outlook and Owncloud. Ok, not seamless, but acceptable. Syncing with FirefoxOS ====================== Adding a calendar is as simple as adding the CalDAV URL in the calendar app. The Contacts application does not support CardDAV, however it can import VCF contacts. So just export contacts from ownCloud’s contacts, copy the file to the phone’s sdcard, and in the Contact application select ‘import from sdcard’. This seems to work well iteratively as well (meaning it will add new contacts, and update old ones, but won’t duplicate contacts). If you’re like me, you’ll have a homebrew certification authority so you’ll need to add your root CA to your FirefoxOS. (And if you have self-signed certificates, think again: it’s really not that much harder to run a home CA, and way more flexible as you only import that one root CA once to all your devices, then all those various certificates for SSMTP, IMAPS, HTTPS, XMPP and so on all work at once).

Syncing with Android

Use the DavDroid application. It’s not free, but it’s what you really want. Add one account for contacts to URL https://cloud.rutschle.net/owncloud/remote.php/carddav and another for https://cloud.rutschle.net/owncloud/remote.php/caldav.

It should be possible to set up some auto-configure in DNS so that DavDroid knows how to find the DAV servers from the DNS, but I need to look into that.

Syncing Outlook calendar towards Owncloud

In Outlook, right-click on the calendar you want to export, select ‘Share’, ‘Share to WebDAV’. This will export your Outlook calendar as a single ICS file to the specified URL, e.g. directly in your ownCloud files. From this point, you can click on the ICS file in the ownCloud Web interface and import the file to a calendar. There are plenty more details here if this isn’t clear for you.

The next step is to automate the import, following e.g. this method, where:

  • OC_ROOT needs to be changed to /usr/share/owncloud (Debian file system).
  • $path needs to point to the ICS file, to something like /var/lib/owncloud/data/$username/files/$Calendrier_de_RUTSCHLE_Yves</b>.ics (adapt the dollars).
  • calendarid is the index number to the calendar (go to the calendar list: the first calendar in the list is 1, the second is 2 and so on)

a crontab for user www-data to import the file regularly (ideally we’d want to run it when the ICS file changes, but…).