Tags:

Backup your CalDav calendar with a Raspberry Pi

One of the basic things that you as a developer must know is how to handle a version control system like git, subversion, Mercurial, you name it..

Chris / / zuletzt aktualisiert am

Once that you have grasped all the benefits of such a version control system, you won’t ever miss that. But you begin to recognize to miss it in a lot of other applications where you want to e.g. track the history.
One of those applications for me is my calendar. Especially if you share your calendar with other people (perhaps not with IT background) a lot of things begin to happen, like missing appointments, moving appointments around, timezone issue and so on.

So one of the basic requirements for me was to backup the CalDav calendar regularly. Unfortunately most of the email providers that offer calendar functionality do not offer such a service that’s why I implemented it myself with the help of a Raspberry Pi 3B.

The script uses the open source software cadaver and should work with CalDAV calendars in general, in my case I use it with calendars from 1&1 email.

All you have to do is install the cadaver client according to the documentation and create a new script e.g. backup-caldav.sh with the following content:

#!/bin/bash
# @see https://uriesk.wordpress.com/2015/02/13/backup-your-caldav-calendar-with-cadaver/

CALDAV_URL=$1
CALDAV_USER=$2
CALDAV_PASSWD=$3

/bin/cat < ~/.netrc
default
login ${CALDAV_USER}
password ${CALDAV_PASSWD}
EOM

set -e

mkdir -p /tmp/calendar
cd /tmp/calendar

cadaver "$CALDAV_URL" << EOA
mget *.ics
EOA

# check if any files were downloaded
compgen -G "*.ics" > /dev/null || exit 1

FILENAME=/tmp/backups/calendar-${CALDAV_USER}-`date +%Y.%m.%d`.tar.bz2

cd ..
tar cvfj "$FILENAME" calendar
rm -r /tmp/calendar
rm ~/.netrc

echo "Backup file $FILENAME successfully completed on `date`."

Then execute the script via e.g. crontab on your Raspberry Pi (or of course any other linux system in your network) with the following command:
./backup-caldav.sh https://your.caldav.url user password

After running this script the resulting backup file will be saved to /tmp/backups.


Reaktionen auf "Backup your CalDav calendar with a Raspberry Pi"

Kommentar erstellen

Mit der Nutzung dieses Formulars erklärst Du Dich mit der Speicherung und Verarbeitung Deiner Daten durch diese Website einverstanden. Informationen zur Verarbeitung Deiner Daten findest Du in der Datenschutzerklärung.
Ihre Daten werden sicher per SSL übertragen.

Meine Magento Extension Bestseller