nextcloud calender contact backup script

Suggestions for features and software you would like to see in DietPi, goes here.
Post Reply
droogi
Posts: 11
Joined: Tue Jan 05, 2021 6:52 pm

nextcloud calender contact backup script

Post by droogi »

Hello Joulinar,

i have a suggestion about a backup script that i found and i am very happy with.
i use calcardbackup (Bash script to backup calendars and addressbooks from a local ownCloud/Nextcloud installation).
So i have an "always working" backup of my calenders and contacts on all devices.
Maybe it is useful for others as well,

https://codeberg.org/BernieO/calcardbackup

Regards, droogi
User avatar
MichaIng
Site Admin
Posts: 3514
Joined: Sat Nov 18, 2017 6:21 pm

Re: nextcloud calender contact backup script

Post by MichaIng »

My goodness, this is a huge script. It seems to have a large feature set, also SQLite and PostgreSQL support (if Nextcloud was manually installed/configured to use it instead of MariaDB), support for encryption, compression and remote transfer of the backup etc etc.

For those who think it is an overkill:

Code: Select all

cat << '_EOF_' > /etc/cron.daily/nextcloud_db_backup
#!/bin/dash

# Enable maintenance mode
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on

# Backup Nextcloud database with numerically sortable timestamp
mysqldump nextcloud > /path/to/backup/$(date +%Y-%m-%d_%T).sql

# Disable maintenance mode
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off

# Remove old backups until max 10 are left
until [[ $(find /path/to/backup -name '*.sql' | wc -l) -le 10 ]]
do
rm -v "$(find /path/to/backup -name '*.sql' | sort -n | head -1)"
done

exit 0
_EOF_
chmod +x /etc/cron.daily/nextcloud_db_backup
So you have a daily running script which creates a whole Nextcloud database backup (instead of calendar/contacts only) and keeps 10 iterations of it.
User avatar
Joulinar
Posts: 6441
Joined: Sat Nov 16, 2019 12:49 am

Re: nextcloud calender contact backup script

Post by Joulinar »

@MichaIng
Should we add this to our NextCloud docs?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
droogi
Posts: 11
Joined: Tue Jan 05, 2021 6:52 pm

Re: nextcloud calender contact backup script

Post by droogi »

what i like in the calcardbackup script:

1. my backupfiles are .ics calenders and .vcf contacts. I am able to handle these with "any" program without a nextcloud installation.
2. i was able to restore these data out of my broken nextcloud installation.

i will try Michalngs short backup suggestion, but i dont know yet how to handle the .sql file.
User avatar
Joulinar
Posts: 6441
Joined: Sat Nov 16, 2019 12:49 am

Re: nextcloud calender contact backup script

Post by Joulinar »

.sql is a full database dump and can be used to restore/recreate your entire NextCloud database on a re-install if needed.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
MichaIng
Site Admin
Posts: 3514
Joined: Sat Nov 18, 2017 6:21 pm

Re: nextcloud calender contact backup script

Post by MichaIng »

Btw I did a little but important syntax fix in the script above.

Since .sql files are not binary but plain text, it can be also used to restore single tables, individual rows or data. I agree that .ics and .vcf files are pretty handy. So basically the question is what you need. I do the database backups to be able to restore the full or parts of the database, when corrupted, on the server itself, to repair a broken Nextcloud server. Calendar/contacts exports can be done at the clients instead, also when the server is dead. But indeed depending on the client removed/broken data could be synced so that a central export/backup to quickly access/restore those on the clients is nice as well.
Post Reply