Repository navigation
fix(backup): resolve version-compatible pg_dump/pg_restore and fall back on PG major version mismatch - #1973
Merged
Merged
Conversation
…er) and fall back to logical dump on version mismatch
Contributor
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: e8605f17-bdc3-4859-a85c-d8ddd522c95a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes PostgreSQL scheduled/manual backup and restore failing on hosts whose distro
postgresql-clientmajor version is older than the running PostgreSQL server (e.g. Ubuntu 22.04pg_dump 14.24againstvm2api-postgrespostgres:18-alpine18.6:aborting because of server version mismatch).src/lib/admin/backup-core.mjs):parsePgMajorVersion(),queryPgServerMajorVersion(),buildDockerPgUri(), andresolvePgTool(tool, { serverMajor, connectionString })shared by bothpg_dumpandpg_restore(SSOT).KIN_PG_DUMP_BIN/KIN_PG_RESTORE_BIN) → hostPATHbinary (only ifmajor >= serverMajor) → Linux PGDG versioned binaries (/usr/lib/postgresql/<N>/bin/<tool>, highest compatible major first) → local managed Docker container (docker exec <VM2API_PG_CONTAINER|vm2api-postgres> <tool>) when the DSN targets loopback (127.0.0.1/localhost/::1).-e PGPASSWORDvia child env so credentials never appear in argv (ps).runPgBackupJob):pg_dumpis available (e.g. remote PG 18 with only hostpg_dump 14), or ifpg_dumpexits withserver version mismatch,runPgBackupJobcleanly falls back to the built-in streamingdumpPgLogicalNdjsonGz()(pg_logical_ndjson_gz), which restores via pure JS without needingpg_restore.src/lib/admin/backup-service.mjs):_pgRestoreAvailable()now queries the live PG server major version and passes{ serverMajor, connectionString }topgRestoreAvailable(), rejecting incompatible custom dumps withpg_restore_missingbefore creatingpre_restoreand allowing container-backedpg_restorewhen available.Test Plan
node --test test/unit/backup-service.test.mjs test/unit/settings-ops-audit.test.mjs— pass (including new unit tests forparsePgMajorVersion,buildDockerPgUri, PGDG / Docker / remote resolution, argv secret safety, andpg_restore_missing)npm run test:ci— all 12 core files passnpx biome formaton the 3 modified files — passNote
Medium Risk
Touches backup/restore of production database state and spawns docker/host PG tools with credentials; logic is complex but includes safe NDJSON fallback and tested preflight paths.
Overview
Fixes PostgreSQL backup/restore when the host
pg_dump/pg_restoremajor is older than the server (e.g. client 14 vs server 18).Version-aware tool resolution in
backup-core.mjs: newresolvePgTool()picks a compatible runner via env overrides (KIN_PG_*_BIN), PATH, PGDG paths under/usr/lib/postgresql/<N>/bin, ordocker execintoVM2API_PG_CONTAINERfor loopback DSNs.execPgDump/execPgRestorerun either a host binary or container tools, streaming I/O via file descriptors and passingPGPASSWORDin env (not argv).Backup path:
runPgBackupJobqueries server major, uses the resolvedpg_dump, and on failure or "server version mismatch" stderr falls back to the existing pure-JSdumpPgLogicalNdjsonGzinstead of hard-failing.Restore path:
restorePgSnapshotJobandBackupServicepreflight now require a version-compatiblepg_restore(async check with live server major) and emit clearerpg_restore_missingerrors when none exists.Unit tests cover PGDG/Docker selection, credential handling, and mismatch fallback behavior.
Reviewed by Cursor Bugbot for commit 9fb8220. Configure here.