From df25e8ce001d6559d5ba7685a9b94ac077c13a0e Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Fri, 3 May 2024 18:03:57 +0200 Subject: [PATCH] fix(nextcloud): Convert from docker to k3s --- scripts/nextcloud/backup-database.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/nextcloud/backup-database.sh b/scripts/nextcloud/backup-database.sh index 6105468..36f0349 100755 --- a/scripts/nextcloud/backup-database.sh +++ b/scripts/nextcloud/backup-database.sh @@ -39,12 +39,14 @@ else destination="${1}" fi +namespace="ix-nextcloud-2" + # Filename for database backup database_backupfile="nextcloud-sqlbkp_$(date +'%Y%m%d').bak" # Retrieve container names -base_container="$( docker ps --format '{{.Names}}' | grep -E 'nextcloud-2_nextcloud-2-[0-9a-z]{10}-[0-9a-z]{5}' )" -database_container="$( docker ps --format '{{.Names}}' | grep postgres_nextcloud-2-cnpg-main-1 )" +base_container="$( k3s kubectl get pods --namespace "${namespace}" | cut -f1 -d' ' | grep -E 'nextcloud-2-[0-9a-z]{10}-[0-9a-z]{5}' )" +database_container="$( k3s kubectl get pods --namespace "${namespace}" | cut -f1 -d' ' | grep 'cnpg-main' )" if ! [[ -n "${base_container}" && -n "${database_container}" ]]; then >&2 printf "Error: Not all containers could be found.\n" @@ -55,21 +57,21 @@ fi set -e # Turn on maintenance mode -docker exec "${base_container}" php occ maintenance:mode --on +k3s kubectl exec "${base_container}" --namespace "${namespace}" -- php occ maintenance:mode --on # Database backup echo 'Backing up database' host_database_backupfile="${destination}/${database_backupfile}" -docker exec --env-file "${env_file:=.env}" "${database_container}" pg_dump 'nextcloud' -cwv -h 'localhost' -U 'nextcloud' > "${host_database_backupfile}" +k3s kubectl exec "${database_container}" --namespace "${namespace}" -- env $(cat "${env_file:=.env}" | xargs) pg_dump 'nextcloud' -cwv -h 'localhost' -U 'nextcloud' > "${host_database_backupfile}" # Files backup for file in 'config' 'themes'; do printf "Copying %s\n" "${file}" - docker cp -a "${base_container}":"/var/www/html/${file}" "${destination}" + k3s kubectl cp "${base_container}":"/var/www/html/${file}" "${destination}" done # Turn off maintenance mode -docker exec "${base_container}" php occ maintenance:mode --off +k3s kubectl exec "${base_container}" --namespace "${namespace}" -- php occ maintenance:mode --off # Backup cleanup # Only keep 30 days of backups