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


I like to backup my Nextcloud calendars and addressbooks as .ics/.vcf files, because it is very easy to restore: just import the backed up .ics/.vcf file to the server or a client and the accidentally deleted data is back online.

Therefore I initially wrote a bash script with hardcoded links for my nextcloud installation. Two friends were interested and so I improved the script to be more generic which possibly makes it interesting for other users as well.

The script downloads all available calendars/addressbooks belonging to certain users from a Nextcloud instance as .ics/.vcf files. Usernames and according passwords have to be given in a separate file. All downloaded files are then compressed to a single file with the current date in the filename.

It works with all currently released Nextcloud versions (and ownCloud >= 5.0) and has been tested under Debian Wheezy, Jessie and Stretch. Of course shell access to the server is needed. Configuration is quite simple: in most cases the path to the Nextcloud directory sufficient. It is not necessary to run the script with root privileges - in default configuration it only needs to have read access to Nextclouds configuration file ‘config.php’. At no point any data leaves the server.

If that sounds interesting to you, you are welcome to use it:

Best wishes,

Automatic backup of calendar entries
Download ics file by script
[Question] Data file location for Contacts and Calendar apps - Snap Installation
[calendar] Kann man ein Backup nur von einem User machen
[Help] Problems in exporting large contacts file
Export all contacts or calendars
How to Keep My Calendar After an Upgrade to New SD Card Installation
Tasks backup by using URLs
Restoring Data from Database Backup
Nextcloud-Snap: question about nextcloud.mysql-client

Thanks for sharing your script with us. Some remarks:

  • why do you need the server-path and the folder on the server? For me it makes more sense to make a backup from an external host (like or just run a backup server-side script for each user (directly use the database, don’t ask the user’s password).
  • Having a file with all users and clear-text passwords on the server is not good
  • Tables can have a prefix different from “oc_”


The folder is needed for reading values of config.php - the URL is only needed, if overwrite.cli.uri is not present in config.php.
Cadaver sounds interesting. I’ll have a look at that. But wouldn’t you need usernames and passwords then as well?
I also thought about directly reading the values from the database. Haven’t read enough into ics-standard though and don’t want to read values, put them somehow together eventually resulting in a non valid ics file. And with only backing up the database tables (with e.g. mysqldump) restoring wouldn’t be as easy as it is with ics/vcf files.

I agree, this is not optimal. The script is mainly meant to be for users who host their own Nextcloud Installation at home with not so many users (e.g. family) and not so many people accessing the server (being able to read that file).

Thanks, didn’t notice that because there is no option to choose a table prefix string when installing Nextcloud. So it might not affect so many people. Anyway: fixed it for the next release.


I just released version 0.2.0 of the script, which comes with a new option to include shared addressbooks/calendars to the backup. This may be used to provide only one username + password in the credentials-file to whom all addressbooks/calendars (to be backed up) are shared. A just for this purpose created new user would make sense. If the file gets somehow in wrong hands, only the credentials of this single user will be compromised.

Drawback of this approach is: added addressbooks/calendars will not be backed up, unless they are shared with that user. That’s the price for improved security…

Have a look at the section “About the option -i / --include-shares” in the file in the github-repo for a detailed “How to”. There you can also find some usage examples:

Cheers, Bernie_O

Problem with contacts after upgrade

I had the honour to help Bernie_O with some translation of documentation for the newest release of this backup script which I find really useful.
But I am writing this to point out to the fact that calcardbackup does not need cleartext passwords (nor usernames) anymore, since it fetches all data directly from the database now. So there’s no security issue anymore to use the script, which at least to me is a better feeling to have backup and security both.

Thanks a lot Bernie_O for your constant work on this script!


You Sir are my absolute hero! The script worked like a charm and everything was perfect. Thank you for your work!