#2 Working nc backup script that copies to a folder

This commit is contained in:
Tibo De Peuter 2023-04-14 00:35:13 +02:00
parent d26ecf5e7c
commit 85f007a4ee

5
backups/create_nextcloud_backup.sh Normal file → Executable file
View file

@ -1,6 +1,8 @@
#!/bin/bash
# Backup script for Nextcloud in a kubernetes cluster
BACKUP_DEST=/mnt/APPS/git/backups
# 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 )
@ -13,7 +15,8 @@ docker exec --user www-data "${nextcloud_container}" php occ maintenance:mode --
# 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
docker exec --env-file ./evars.txt "${database_container}" pg_dump "nextcloud" -cwv -h "localhost" -U "nextcloud" -f /tmp/nextcloud-sqlbkp_`date +"%Y%m%d"`.bak
docker cp "${database_container}":/tmp/nextcloud-sqlbkp_$(date +"%Y%m%d").bak /mnt/APPS/git/backups
# Turn off maintenance mode
docker exec --user www-data "${nextcloud_container}" php occ maintenance:mode --off