Skip to content

feat(backup): add File > Backup… for PostgreSQL via pg_dump#1210

Closed
samirmhsnv wants to merge 2 commits into
TableProApp:mainfrom
samirmhsnv:feat/backup-postgres-pg-dump
Closed

feat(backup): add File > Backup… for PostgreSQL via pg_dump#1210
samirmhsnv wants to merge 2 commits into
TableProApp:mainfrom
samirmhsnv:feat/backup-postgres-pg-dump

Conversation

@samirmhsnv
Copy link
Copy Markdown

Summary

  • New File > Backup… menu item for PostgreSQL and Redshift connections. Pick a database, choose a destination, runs pg_dump -Fc with live byte progress and cancel.
  • Reuses the connection's active SSH tunnel via session.effectiveConnection, so tunneled connections work without opening a second port forward.
  • pg_dump is auto-detected from PATH and common Homebrew locations. Override under Settings > Terminal > CLI Paths > pg_dump.

Notes for reviewers

  • DatabaseSwitcherSheet gains a Mode enum (.switch default, .backup). Existing call sites stay on the default and are unchanged. In backup mode the schemas tab and create/drop affordances are hidden, the primary button reads "Back Up…", and the callback does not auto-dismiss so the host sheet can transition to the save panel.
  • PostgresBackupService polls file size every 250ms for progress (pg_dump has no progress hook). Cancel sends SIGTERM and removes the partial file. Stderr is captured (capped at 64KB) and shown on failure.
  • SSL mode raw values are mapped to libpq's PGSSLMODE values (require, verify-ca, verify-full, etc.) instead of being passed through verbatim.
  • --no-password is passed to pg_dump so it fails fast with an auth error instead of hanging on a TTY prompt when PGPASSWORD is missing.
  • Headless xcodebuild from CLI fails locally on a SwiftLint plugin sandbox issue in CodeEditTextView/CodeEditSourceEditor (unrelated to this change). SwiftLint --strict is clean on every changed file. Verify the build from Xcode.

Test plan

  • Postgres connection without SSH: open Backup…, pick a DB, save, verify the .dump file is a valid custom-format archive (pg_restore -l file.dump).
  • Postgres connection with SSH tunnel: same flow, verify it uses the existing tunnel (no second port forward in lsof).
  • Cancel mid-backup: confirm the partial file is removed and the sheet shows "Backup Cancelled".
  • Non-Postgres connection: Backup… menu item is disabled.
  • Custom pg_dump path: set under Settings > Terminal > CLI Paths > pg_dump, verify it is used.
  • No pg_dump on system: backup fails with the install hint.
  • Redshift connection: backup works (Redshift shares the PostgreSQL plugin).

Picks a database from the current connection, prompts for a destination, and
runs pg_dump with the custom archive format (-Fc), surfacing live byte
progress and a cancel that cleans up the partial file. Reuses the active
SSH tunnel via session.effectiveConnection so tunneled connections work
without spinning up a second tunnel. pg_dump path is auto-detected from
PATH and common Homebrew locations, with an override under Settings >
Terminal > CLI Paths.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

Thank you for your contribution! Before we can merge this PR, you need to sign our Contributor License Agreement.

To sign, please comment below with:

I have read the CLA Document and I hereby sign the CLA.


I have read the CLA Document and I hereby sign the CLA.


1 out of 2 committers have signed the CLA.
✅ (samirmhsnv)[https://github.com/samirmhsnv]
@samir Mammadhasanov
Samir Mammadhasanov seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@samirmhsnv
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA.

Picks a .dump file via NSOpenPanel, then a target database on the current
PostgreSQL or Redshift connection, then runs pg_restore --no-owner --no-acl
with progress and cancel. Reuses the active SSH tunnel via
session.effectiveConnection. pg_restore path is auto-detected with a custom
override under Settings > Terminal > CLI Paths.

The backup progress and result sheets gain a Kind enum so both flows share
them. DatabaseSwitcherSheet gains a .restore mode alongside .backup; both
hide the schemas tab and create/drop affordances and hand the selection to
the parent flow without auto-dismissing.
github-actions Bot added a commit that referenced this pull request May 11, 2026
@samirmhsnv
Copy link
Copy Markdown
Author

Superseded by #1211, which covers both Backup and Restore with a combined description and test plan.

@samirmhsnv samirmhsnv closed this May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant