#2 WIP Nextcloud db backup

This commit is contained in:
Tibo De Peuter 2023-01-14 23:59:00 +01:00
parent 0f278f2258
commit d4663d0ce1

View file

@ -0,0 +1,21 @@
#!/bin/bash
# Backup script for Nextcloud in a kubernetes cluster
# Retrieve container names
nextcloud_container=$( docker ps --format "{{.Names}}" | grep hugocloud-nextcloud_hugocloud-nextcloud )
database_container=$( docker ps --format "{{.Names}}" | grep hugocloud-postgresql_hugocloud-postgresql )
# Abort entire script if any command fails
set -e
# Turn on maintenance mode
docker exec --user www-data "${nextcloud_container}" php occ maintenance:mode --on
# Database backup
>&2 echo "Backing up database"
docker exec "${database_container}" pg_dump "nextcloud" -cwv -h "localhost" -U "nextcloud" -f nextcloud-sqlbkp_`date +"%Y%m%d"`.bak
# Turn off maintenance mode
docker exec --user www-data "${nextcloud_container}" php occ maintenance:mode --off
>&2 echo "Done"