docker icon indicating copy to clipboard operation
docker copied to clipboard

Whats the proper way to backup a nextcloud docker instance?

Open sooonmitch opened this issue 3 years ago • 2 comments

I currently have the nextcloud /var/www/html directory attached to an external volume on my server. I then backup this directory and all its contents to another server. Is this the proper way to backup the Nextcloud docker image? Is there a better way of doing this?

I can't seem to find any documentation on this and haven't found a Github issue on this subject. Any help would be awesome.

sooonmitch avatar Jul 11 '21 00:07 sooonmitch

Take a look at the official docs at admin_manual/maintenance/backup. I also got some inspiration from nextcloud-backup-erstellen-und-wiederherstellen-in-docker-umgebung

Perhaps something similar like that:

#!/bin/bash

db_container="docker_db_1"
db_backup_dir="/some_backup_destination_path/mariadb"

app_container="docker_app_1"
app_data_dir="/some_nextcloud_data_volume/nextcloud"
app_backup_dir="/some_backup_destination_path/nextcloud"

docker exec --user www-data "${app_container}" php occ maintenance:mode --on

rsync -Aavx "$app_data_dir/" "$app_backup_dir/nextcloud-dirbkp"

docker exec "${db_container}" sh -c 'exec mysqldump --default-character-set=utf8mb4 --single-transaction -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE"' > "$db_backup_dir/nextcloud-sqlbkp.bak"

docker exec --user www-data "${app_container}" php occ maintenance:mode --off

guste-github avatar Jul 12 '21 16:07 guste-github

@guste-github Thank you for the script. Do you by chance have a restore script to go along with this?

Also, I am honestly really surprised that the docker image doesn't have something built in. Perhaps have a "backup_cron" env variable, that if set, would trigger the above script automatically. Also, possibly a restore srcript built also. Would be an awesome update/feature for people running/managing this for personal use.

sooonmitch avatar Jul 13 '21 03:07 sooonmitch