Posted on Sun 31 October 2021 in linux

To avoid data loss, it is always a good idea to backup your data. If you are using a CalDav server to manage your calendar items or a CardDav server to manage your address book, it is worthwhile to also backup this sort of data since it may contain private data that will be hard to recover in case of a data loss.

A handy tool to backup caldav and carddav data is vdirsyncer that allows the synchronization of calendar and address book data in an easy fashion.

vdirsyncer can be simply installed from the Debian repositories:

sudo apt install vdirsyncer

After the installation, a config file must be created. A simple way to start with the config is to use the provided example file and ensure that it is only readable by the user (particularly if you store your credentials here):

mkdir ~/.config/vdirsyncer
cp /usr/share/doc/vdirsyncer/examples/config ~/.config/vdirsyncer/config
chmod 0600  ~/.config/vdirsyncer/config

Now adapt the config file ~/.config/vdirsyncer/config to your needs. The config is straight forward, mostly depending on the servers you are using and the corresponding credentials.

When you are done with the configuration, refresh the collection caches for all pairs (needs to be repeated for new collections):

vdirsyncer discover

Synchronize all known collections:

vdirsyncer sync

If everything is working as expected, simply activate the corresponding systemd timer that will run 15m per default:

systemctl --user enable vdirsyncer.timer

You can check the latest logs with:

journalctl --user -u vdirsyncer

That's it. From now on your calendar and address book data is regularly synchronized so that always a backup should be available. Additional layers of protections could be added by using an underlying git repository to track the changes, but this is beyond this article.