How to backup a Nextcloud-installation with Docker

Hey I am new here and also new to the whole Docker universe in general, so I just want to apologize first of all for this unsophisticated post.

I did a fresh nextcloud install in my OMV via the GUI with MariaDB and LetsEncrypt. Everything works just fine but I was asking myself how to do automated backups of my data and the whole installation in a sufficient way. I connected a second external drive to my server tried to follow the steps discribed in the nextcloud documentation- unfortunately i was not able to write a working script to backup everything.

Here are the bash commands I tried to use:

docker exec -it nextcloud bash
sudo -u abc php /config/www/nextcloud/occ maintenance:mode --on
exit
tar -cpzf /sharedfolders/Next_Backup/nextcloud_files_$now.tar.gz /sharedfolders/Nextcloud-Data/
docker exec mariadb sh -c exec mysqldump --single-transaction -h localhost -u 1000 -p100 nextcloud > /sharedfolders/Next_Backup/nextcloudDB_1.sql
docker exec -it nextcloud bash
sudo -u abc php /config/www/nextcloud/occ maintenance:mode --off

i was able to create backupfiles of the Data and the Database… but I want to automate the process… is this possible? And How? Or is there a better way?

Thank you very much! :slight_smile:

I just edited a bit your commands to write a simple shell script :stuck_out_tongue:

#!/bin/bash
set -e
now=${now:-"$(date '+%Y%m%d_%H%M%S')"}
docker exec -it nextcloud bash <<END
sudo -u abc php /config/www/nextcloud/occ maintenance:mode --on 
END
tar -cpzf /sharedfolders/Next_Backup/nextcloud_files_$now.tar.gz /sharedfolders/Nextcloud-Data/ 
docker exec mariadb sh -c exec mysqldump --single-transaction -h localhost -u 1000 -p100 nextcloud > /sharedfolders/Next_Backup/nextcloudDB_1.sql 
docker exec -it nextcloud bash <<END
sudo -u abc php /config/www/nextcloud/occ maintenance:mode --off
END

Thank you so much- I will try to test it during the next week! :smiley: