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 / / last updated on

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.


Post Comments to "Backup your CalDav calendar with a Raspberry Pi"

Submit Comment

With the use of this comment form you agree to the saving and processing of your data by this website. More information about the processing of your data can be found in our privacy statement.
Your data will be transmitted securely via SSL.

Meine Magento Extension Bestseller