Importing an Immich DB backup into a new CNPG database¶
This is the alternate Immich DB restore path — for when you have an Immich-format SQL dump (from Immich's built-in backup) rather than a Barman-cloud backup. For the standard Barman recovery path used after a cluster rebuild, see Cluster Rebuild; for the offsite-S3 path, see Offsite Recovery.
Procedure¶
- Create the target database:
- Confirm you're against the primary (writes go to the primary; replicas are read-only):
- Stream the dump in via the Immich restore command. The
sedrewrite is required because Immich uses extensions whosesearch_pathneeds to be set explicitly during restore:
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 <cluster-name> --
- Verify the row counts after restore (replace
<dump-row-count>with what you'd expect from the source):
When to use this vs the Barman path¶
| Situation | Use |
|---|---|
| Cluster rebuild, Barman backups in Garage | Cluster Rebuild → CNPG recovery from Garage |
| Total loss, only S3 offsite backup survives | Offsite Recovery → Step 4: Restore the database via Barman |
Have a pg_dump from inside Immich (admin → "Job Status" → backup) |
This doc. |
| Migrating Immich data between environments | This doc. |