fix(vaultwarden): Convert from docker to k3s

This commit is contained in:
Tibo De Peuter 2024-05-03 18:34:11 +02:00
parent 7f801e6430
commit 484b601bc0
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2

View file

@ -41,9 +41,11 @@ else
destination="${1}" destination="${1}"
fi fi
namespace="ix-vaultwarden-2"
# Retrieve container names # Retrieve container names
base_container="$( docker ps --format '{{.Names}}' | grep -E 'vaultwarden-2_vaultwarden-2-[0-9a-z]{10}-[0-9a-z]{5}' )" base_container="$( k3s kubectl get pods --namespace "${namespace}" | cut -f1 -d' ' | grep -E 'vaultwarden-2-[0-9a-z]{10}-[0-9a-z]{5}' )"
database_container="$( docker ps --format '{{.Names}}' | grep postgres_vaultwarden-2-cnpg-main-1 )" database_container="$( k3s kubectl get pods --namespace "${namespace}" | cut -f1 -d' ' | grep 'vaultwarden-2-cnpg-main-1' )"
if ! [[ -n "${base_container}" && -n "${database_container}" ]]; then if ! [[ -n "${base_container}" && -n "${database_container}" ]]; then
>&2 printf "Error: Not all containers could be found.\n" >&2 printf "Error: Not all containers could be found.\n"
@ -59,14 +61,14 @@ set -e
database_backupfile="vaultwarden-sqlbkp_$(date +'%Y%m%d').bak" database_backupfile="vaultwarden-sqlbkp_$(date +'%Y%m%d').bak"
host_database_backupfile="${destination}/${database_backupfile}" host_database_backupfile="${destination}/${database_backupfile}"
# Create backup file in docker container # Create backup file in Kubernetes pod
echo 'Backing up database' echo 'Backing up database'
docker exec --env-file "${env_file:=.env}" "${database_container}" pg_dump 'vaultwarden' -cwv -h 'localhost' -U 'vaultwarden' > "${host_database_backupfile}" k3s kubectl exec "${database_container}" --namespace "${namespace}" -- env $(cat "${env_file:=.env}" | xargs) pg_dump 'vaultwarden' -cwv -h 'localhost' -U 'vaultwarden' > "${host_database_backupfile}"
# Files backup # Files backup
for file in 'attachments' 'sends' 'rsa_key.pem' 'rsa_key.pub.pem'; do # 'config.json' for file in 'attachments' 'sends' 'rsa_key.pem' 'rsa_key.pub.pem'; do # 'config.json'
printf 'Copying %s\n' "${file}" printf 'Copying %s\n' "${file}"
docker cp -a "${base_container}":"/data/${file}" "${destination}" k3s kubectl --namespace "${namespace}" cp "${base_container}":"/data/${file}" "${destination}"
done done
# Backup cleanup # Backup cleanup