Skip to content

feat(backup): overhaul backup/restore — per-dialect clients, driver-based Redis/ClickHouse, bug fixes - #41

Open
paulocastellano wants to merge 8 commits into
mainfrom
refactor/backup-restore-overhaul
Open

feat(backup): overhaul backup/restore — per-dialect clients, driver-based Redis/ClickHouse, bug fixes#41
paulocastellano wants to merge 8 commits into
mainfrom
refactor/backup-restore-overhaul

Conversation

@paulocastellano

Copy link
Copy Markdown
Contributor

Resumo

Reescreve o sistema de backup/restore que era frágil ("dava vários paus"): o src/main/services/backup.ts monolítico (1436 linhas) virou uma arquitetura modular espelhando o Beekeeper Studio (1 cliente por dialeto), e os 5 bugs de runtime foram corrigidos — verificados end-to-end contra bancos reais via Docker.

backup.ts: 1436 → ~590 linhas.

Bugs corrigidos (verificados contra containers)

  • Redis irrestaurável--rdb (não restaurável via --pipe) → driver SCAN/DUMP/RESTORE + TTL, funciona por SSH.
  • ClickHouse via SSH + full=só-DDL → driver HTTP exportando DDL e dados (servidor gera os INSERTs via FORMAT SQLInsert).
  • MongoDB multi-collection silencioso → um mongodump -c por collection (sem dump silencioso do banco inteiro); --authenticationDatabase alinhado ao driver.
  • Log truncado → mantém cabeça + cauda.
  • Extras: limpa arquivo parcial em cancel/erro; default utf8mb4 (MySQL) e UTF8 (PostgreSQL) para preservar emoji/multibyte.

Arquitetura

  • BaseCommandClient + clientes por dialeto em backup-clients/ e restore-clients/, via factory commandClientsFor().
  • Caminho por driver (Redis/ClickHouse) para cenários sem ferramenta oficial viável.
  • PostgreSQL: formatos plain / custom (-Fc) / directory (-Fd -j) com restore via pg_restore (formato auto-detectado pelo magic PGDMP / diretório).
  • Opções por dialeto na UI (formato/encoding/charset) + nova tela de progresso (esconde o comando cru em "Technical details").
  • splitSqlStatements extraído para @main/utils/sql (desacopla serviço da camada IPC).

Testes

  • Unit por cliente + cobertura das novas lógicas (loop extraCommands, caminho driver, limpeza de parcial).
  • Integração round-trip real (popular → backup → limpar → restore → comparar, com emoji/multibyte) para Redis, ClickHouse, MongoDB, PostgreSQL (plain/custom/directory), MySQL, SQLite.
  • Suíte: 4677 unit + integração verdes, typecheck node+web limpo, build de produção OK.

Code review

Passou por code review (8 ângulos): 1 bug real (escaping ClickHouse) corrigido, convenções alinhadas (imports @main/, enum PgDumpFormat), lacunas de teste cobertas.

Notas / limitações conhecidas

  • SQL Server / DuckDB: clientes refatorados e cobertos por testes de build-command; sem round-trip real (binários ausentes no ambiente).
  • Testes de integração pulam graciosamente sem container — recomenda-se um gate de CI que falhe se o Docker deveria estar presente.
  • Cleanup/DRY menores (máscara de senha, merge cert SSL) deixados para PR separado.

🤖 Generated with Claude Code

…ased Redis/ClickHouse, fixes

Refactor the monolithic 1436-line backup.ts into a Beekeeper-style architecture and fix
the long-standing runtime bugs, verified end-to-end against real databases.

Architecture (Phases 1-2):
- Extract helpers into focused modules (process-args, ssl-temp, archive, BinaryFinder, models)
- BaseCommandClient + one client per dialect under backup-clients/ and restore-clients/,
  wired by commandClientsFor(); backup.ts now only orchestrates
- Extract splitSqlStatements to a pure util (decouple service from the IPC layer)

Bug fixes (Phases 3, 5):
- Redis: unrestorable --rdb replaced with driver-based SCAN/DUMP/RESTORE + TTL
- ClickHouse: works over SSH (HTTP driver) and now exports data, not DDL-only
- MongoDB: multiple collections backed up per-collection, never a silent full-db dump;
  add --authenticationDatabase to match the driver
- Delete partial artifacts on cancel/error; keep log head+tail instead of tail-only

Options & performance (Phase 4):
- PostgreSQL format: plain / custom (-Fc) / directory (-Fd) with parallel jobs and
  pg_restore-based restore (format auto-detected by PGDMP magic / directory)
- MySQL default charset utf8mb4 and PostgreSQL encoding UTF8 so emoji/multibyte survive

UI (Phase 6):
- StepExecute rebuilt around progress (raw command/log moved behind "Technical details")
- StepConfigure exposes format / encoding / charset / parallel-jobs

Tests:
- Per-client unit tests; Docker round-trip integration tests for Redis, ClickHouse,
  PostgreSQL (plain/custom/directory) and MongoDB, all asserting emoji/multibyte integrity
- Fix pre-existing utils.test.ts navigator stub; fix backup-restore integration credentials
- Fix incomplete escaping in clickhouse-serializer (escape backslash before quote,
  matching the driver's escapeValue) to prevent SETTINGS string break-out
- Replace relative ../ imports with @main/ aliases across backup/ (CLAUDE.md rule)
- Introduce PgDumpFormat enum instead of string literals for the pg_dump format
- Add unit tests for the two untested paths: partial-artifact cleanup on failure,
  and the driver-based Redis backup (no spawned binary)
Behavior-preserving deduplication (all tests stay green):
- getStringOption + maskFlagValue helpers in process-args; use across MySQL/PG clients
- appendMongoTlsArgs helper in ssl-temp; replaces the duplicated Mongo TLS block in the
  Mongo backup and restore clients
- Collapse runRestore's three near-identical stdin-piping branches into one pipeStdin
  decision + a shared attachInputStream helper
…uard, types)

- Driver-based dialects (Redis/ClickHouse) now show "runs over the connection" in the
  command preview instead of a misleading CLI command — and no longer surface the
  binary client's ClickHouse-over-SSH error in the preview (the driver path works over SSH).
  Implemented at the IPC layer (driverPreviewSpec) so the service stays fully unit-tested.
- Relax binaryPath validation to allow empty for driver dialects; execute handlers still
  require a binary for binary-based dialects.
- Replace `as any` on Redis zadd with an explicit variadic signature.
- Add requireOrSkip db-guard: integration tests FAIL instead of silently skipping when
  REQUIRE_DB_TESTS=1, preventing false-green CI without Docker. Applied to the round-trips.
- Add unit test for appendMongoTlsArgs (cert+key PEM concat + temp-file tracking).
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