Skip to content

Implement SSH support for database adapters and enhance UI#12

Merged
Skyfay merged 15 commits intodevfrom
ssh-tunneling
Mar 29, 2026
Merged

Implement SSH support for database adapters and enhance UI#12
Skyfay merged 15 commits intodevfrom
ssh-tunneling

Conversation

@Skyfay
Copy link
Copy Markdown
Owner

@Skyfay Skyfay commented Mar 29, 2026

No description provided.

Skyfay added 15 commits March 28, 2026 13:30
Introduce SSH-based execution for database adapters and the test SSH route. Adds a new SSH client library (src/lib/ssh/*) and integrates SSH handling into MySQL, PostgreSQL, MongoDB (and related dump/restore flows) to detect remote binaries, run commands, and stream dumps/restores over SSH. Update the test-ssh API route to use SshClient and split MSSQL SFTP-specific checks from generic SSH exec tests. UI updated to expose an SSH tab and reusable SshConfigSection for adapters that support connectionMode. These changes enable remote CLI-based backup/restore operations and remote database inspection when direct TCP connections are not available.
Add support for adapters with a connectionMode field: render a config.connectionMode SchemaField in the adapter form (except for sqlite) and introduce an SshAwareTabLayout that displays the connection mode selector first and then shows contextual tabs (SSH / Connection / Configuration) based on the selected mode. This forces remount on mode change so the active tab resets correctly. Also update changelog and add a small import adjustment.
Update alignment of the "Detected: {version}" badge in src/components/adapter/form-sections.tsx by replacing `justify-end` with `justify-start` in DatabaseFormContent and SshAwareTabLayout so the badge is left-aligned.
When no database is provided, the dump function no longer throws immediately. It now imports getDatabases, logs that it's backing up all databases, fetches the database list from the server and logs the found DBs; an error is still thrown if no databases are found. This enables backing up the entire MySQL/MariaDB server when no specific database is given.
Document SSH remote-exec connection mode across the project and add silent polling for adapter health.

- README and site index: add "Connection Modes" column and note SSH/Direct support per database.
- User & developer docs: extensive SSH mode docs added for MySQL, MariaDB, PostgreSQL, MongoDB, Redis, SQLite and core adapter/architecture docs (fields, prerequisites, tooling, examples, and SSH architecture).
- src: AdapterManager now performs a silent background refresh (every 10s) to keep adapter health/status up to date without showing spinners or error toasts.
- Changelog: note UI auto-refresh, SSH docs, and a MySQL bugfix for jobs with no DB selected.

These changes add documentation and UX improvements for SSH-based backup workflows and keep source/destination health indicators fresher in the UI.
When no databases are specified for a PostgreSQL backup, dump() now auto-discovers databases via getDatabases(config), logs the discovered list, and errors if none are found. Adds the necessary import and updates the changelog to document the new behavior.
Handle SSH edge cases and harden remote restores across adapters; add SFTP uploads, better exit/signal handling, log rate-limiting and secret redaction, plus related UI/metadata fixes.

Key changes:
- Treat null exit codes and include signal info in SSH exec errors for MongoDB, MySQL, Postgres and Redis.
- Add SshClient.uploadFile and switch SSH restores (MySQL, Postgres) to upload-then-restore to avoid data loss when piping via exec streams.
- Add MySQL-specific hardening: --net-buffer-length on dump, --max-allowed-packet on client, stderr handler that redacts secrets and rate-limits logs, post-failure diagnostics, and safer SSH restore flow.
- Consume stdout for MongoDB/MySQL SSH restores to avoid backpressure hangs.
- Change remoteEnv to use export statements to avoid leaking secrets in kill reports.
- Restore UI: show server-adapter specific target DB name input when db names unknown and pass sourceType metadata for frontend; truncate long adapter names in selects.
- Post-dump auto-discovery of DB names and minor runner metadata fixes.
- Update changelog and developer guide to document these changes and security improvements.

These changes address OOMs, partial uploads, signal handling, noisy logs, and UX gaps during restores.
Switch SSH restore flow for MongoDB and SQLite from piping archives over exec stdin to uploading the file via SFTP and running the restore remotely. Add remote temp filenames (crypto.randomUUID), upload size verification, and remote temp-file cleanup. Remove local stream piping, run mongorestore/sqlite on the remote server using the uploaded file, and surface progress. Update imports and adjust logging/err handling accordingly; update changelog to reflect SFTP switch for MongoDB and SQLite.
Add a "Test SSH Connection" button and handler to the SQLite adapter UI that posts mapped SQLite config to the generic /api/adapters/test-ssh endpoint and shows progress/toasts. Refactor SQLite SSH logic to use shared SSH utilities: extractSqliteSshConfig and remoteBinaryCheck, ensure SSH client connections are always closed with try/finally, and validate SSH config early. Improve getDatabasesWithStats to reuse extracted ssh config and finalize client cleanup. Fix remote dump exit handling to account for nullable exit codes and include signal info in error messages. Clean up unused ssh2 types import and update changelog entries to reflect these changes for reliability and unified SSH behavior across adapters.
Add robust SSH handling and auto-discovery for MongoDB adapters. Use a dedicated logger child for MongoDB connection operations and redact inline passwords in debug logs. Switch mongosh --eval to single-quoted print(JSON.stringify(...)) invocations to avoid bash history expansion and produce machine-friendly JSON output; parse JSON lines from stdout (with a line-based fallback) and include stderr/stdout in error messages. Import getDatabases into the MongoDB dump flow and auto-discover databases when none are selected (with graceful warning on failure). Update the dump runner step to attempt fetching DB names for metadata when an empty selection is provided. Also update changelog entries to reflect the new auto-discovery and mongosh quoting fix.
Constrain the Download Link modal height and make its body scrollable to prevent the dialog from overflowing the viewport when a link is generated. Added max-h and overflow handling to DialogContent and wrapped the modal content in an overflow-y-auto container so file info, mode selection and generated URL can scroll independently. Also updated the changelog with a brief UI fix note.
Render a small "Beta" badge next to the "SSH" option in the select menu to indicate it's experimental. This is a presentational change in src/components/adapter/schema-field.tsx that replaces the plain "ssh" label with an inline span including styling for the badge; no behavioral changes were made.
Show skeleton placeholders and loading text on the Restore page while target databases are being fetched. The restore UI now renders a skeleton row during target DB loading, shows a "Loading target databases..." label in the analysis card, and adds an extra skeleton line. The Restore button is also disabled while target DBs are loading or analysis is running to prevent premature actions. Updated changelog to document the UX improvement.
Cleanup unused imports/variables and update tests: remove unused useEffect import in form-sections.tsx, remove remoteEnv import from mongodb connection, and remove unused processedSize/lastProgress vars in mysql restore. Also update unit tests for MongoDB, MySQL, and Postgres to include connectionMode: 'direct' in the baseConfig so tests satisfy schema/validation requirements.
Add comprehensive unit tests for shared SSH utilities and update the changelog. A new test suite tests/unit/lib/ssh/utils.test.ts (~60 tests) covers shellEscape, remoteEnv, isSSHMode, extractSshConfig, extractSqliteSshConfig, and argument builders for MySQL, PostgreSQL, MongoDB, and Redis. Also update wiki/changelog.md to document the added tests.
@Skyfay Skyfay merged commit f339e15 into dev Mar 29, 2026
@Skyfay Skyfay deleted the ssh-tunneling branch April 2, 2026 09:00
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