How to download all my caldav and carddav data with one wget / curl?

amw picture amw · Apr 12, 2014 · Viewed 9.6k times · Source

Until now, I used Google Calender and do my personal backup with a daily wget of the public ".ics"Link.

Now I want to switch to a new Service who has only caldavaccess.

Is there a possibility to download all my caldav and carddav data with one wget / curl?

This downloaded data should give me the possibility to backup lost data.

Thanks in advance.

edit

I created a very simple php file which works in the way hmh explained. Don't know if this way works for different providers, but for mailbox.org, it works well.

You can find it here https://gist.github.com/ahemwe/a2eaae4d56ac85969cf2.

Answer

hnh picture hnh · Apr 15, 2014

Please be more specific, what is the new service/server you are using?

This is not specifically CalDAV, but most DAV servers still provide a way to grab all events/todos using a single GET. Usually by targeting the relevant collection with a GET, e.g. like either one of those:

curl -X GET -u login -H "Accept: text/calendar" https://myserver/joe/home/
curl -X GET -u login -H "Accept: text/calendar" https://myserver/joe/home.ics

In CalDAV/CardDAV you can grab the whole contents of a collection using a PROPFIND:

curl -X PROPFIND -u login -H "Content-Type: text/xml" -H "Depth: 1" \
  --data "<propfind xmlns='DAV:'><prop><calendar-data xmlns='urn:ietf:params:xml:ns:caldav'/></prop></propfind>" \
  https://myserver/joe/home/

Replace calendar-data with

<address-data xmlns="urn:ietf:params:xml:ns:carddav"/>

for CardDAV.

This will give you an XML entity which has the iCal/vCard contents embedded. To restore it, you would need to parse the XML and extract the data (not hard).

Note: Although plain standard, some servers reject that or just omit the content (lame! file bug reports ;-).