Importing an Immich DB backup into a new CNPG database

  1. Create the new Immich database

kubectl cnpg -n databases psql postgres-16 -- -c 'CREATE DATABASE immich;'

  1. Ensure that you're woring with the primary CNPG instance

kubectl cnpg -n databases status postgres-16 | grep "Primary instance:"

  1. Copy the database backup into the container's persistent storage (where there is likely enough room for it)

kubectl -n databases cp ./immich-db-backup.sql.gz postgres-16-2:/var/lib/postgresql/data/

  1. Exec into the postgres container

kubectl -n databases exec -it postgres-16-2 -- bash

  1. Run the Immich restore command

gunzip < "immich-db-backup-1735455600013.sql.gz"| sed "s/SELECT pg_catalog.set_config('search_path', '', false);/SELECT pg_catalog.set_config('search_path', 'public, pg_catalog', true);/g" | kubectl cnpg -n databases psql postgres-14 --