Calcardbackup: bash script to backup Nextcloud calendars and addressbooks as *.ics/*.vcf files

It may be worth to take a look at vdirsyncer. It syncs calendar/card data from a server (e.g. nextcloud) to local files/folders.
And it can perform 2-way sync, so you can use other tools on your local files and the changes will be synched back.

vdirsyncer and calcardbackup have quite different use cases:

  • vdirsyncer syncronizes calendars/addressbooks of a single user. A single username/password combination must be given in a configuration file.

  • calcardbackup is meant as a backup solution for every single calendar and addressbook found in the database of Nextcloud/ownCloud without the need to give any usernames or passwords.

I just move servers and had to reinstall nextcloud and I wanted to say a big THANK YOU for saving me hours of trying to recover my user’s calendar!

1 Like

Thanks for this nice script! Excellent work!

Just the “–include-shares” option doesn’t work as expected, I still get this message:

Skipping calendar 'xxxxxxxxxxxxxx_shared_by_yyyyyy': already saved as 'yyyyy.ics"

Thank you :slight_smile:

That is actually intended behaviour as mentioned in the options-section of the README:

-i | --include-shares
       Backup shared addressbooks/calendars, too. Items will only be backed up once: e.g. a shared
       calendar won't be backed up if the same calendar was already backed up for another user.

I don‘t see a point of exporting exactly the same calendar twice.

But maybe you can convince me to overthink that. Is there a certain reason you need the file twice?

Well, the way that this option is named and described, suggest otherwise: without this option, each calendar will not be backed up more than once, and if you want shared calendars to be saved for each user, this option has to be used.

The option -i has been introduced for legacy versions of calcardbackup (when users’ credentials had to be passed to the script) to give a possibility to not expose users’ passwords. Starting with calcardbackup v0.8.0 the script reads all required data directly from the database without the need to pass any usernames/passwords to the script. In my opinion, that makes option -i obsolete (a while ago I actually thought about removing this option).

Changing the behaviour of a long time available option, is a step that requires a good reason - and I still can not see a reason to backup the same identical item more than once. Additionally, backing up shared calendars/addressbooks more than once can be very time consuming, which may be a problem for larger instances (e.g. several thousand users). So I’d rather leave it as it is - Sorry.

If you really need this though:
the script can easily be changed to backup shared calendars more then once. All you need to do is to comment out this line. Be aware that the change might get overwritten if you pull a new version. So you need to redo the change after every update.

I can not see a description that says so in the current documentation of calcardbackup. Could you tell exactly where you did get that impression so that I can correct the documentation?

Ok, I understand it now!

The misunderstanding was due to the combination of the option’s name and its explanation: the option is called “include-shares”, and the explanation says:

Backup shared addressbooks/calendars, too.

That can lead to the impression that you if you use it, shared calendars will be saved.

Once you are under that impression, the next sentence, saying that

Items will only be backed up once: e.g. a shared calendar won’t be backed up if the same calendar was already backed up for another user.

automatically sounds like “this will happen if you don’t use this option”.

I guess I would not have fallen for this misinterpretation, if those two sentences were linked by the word “but”:

Backup shared addressbooks/calendars, too, but every item will only be saved once!

Something like this, maybe. :slight_smile:

By the way…

In another thread I was asking about an add on that does what your script does, and that will be configurable via NextCloud’s GUI. The reason for this question is, that even an NC admin does not always have shell access to the server, so your script can not be used.

On the other hand I think it is very important to have a very fast and easy way of regaining the users calendars and contacts, if the server would crash or the data base would corrupt, while NC is still running. Letting the users access backups of their calendars as ical files, would be the fastest way to let them restore their calendars and contacts.

You script does exactly that: extracting the calendars and contacts, and copy the archives to the users file sharing area, where they can be downloaded. But if the admin can not ssh into the server, your script can not be used.

So, my question is: would it be very difficult to turn your script into an add on that the admin can configure in NC’s gui to provide this kind of function?

I see. Thanks for your input. I‘ll rephrase the explanation of the option.

I don’t think this is possible, because you would definitely run into webserver/PHP related timeout problems due to script execution time.