Skip to content

PostgreSQL backup tool with Point-In-Time-Recovery and restore verification

6.7 KB
Raw Blame

1. Backend

  • 1.1 Create the migration stub with goose -dir backend/migrations create add_postgresql_exclude_table_data sql and fill it to add exclude_table_data TEXT NOT NULL DEFAULT '' to postgresql_logical_databases in Up and drop it in Down. Add ExcludeTableData []string (json:"excludeTableData", gorm:"-") and ExcludeTableDataString (column exclude_table_data) to PostgresqlLogicalDatabase, convert them in BeforeSave and AfterFind, assign the list in Update and clone it in CopyForNewDatabase. Extend Test_UpdateDatabase_WhenExcludeTablesArePastedMultiline_StoresTrimmedUniqueNames in backend/internal/features/databases/controller_test.go so the data-excluded list is pasted unnormalized and read back trimmed and unique, add a controller test that creates a database with a data-excluded list, reads it back with that list, copies it and finds the list on the copy, then updates the original without excludeTableData and reads it back with an empty list, and add ExcludeTableData to the filled PostgreSQL model in backend/internal/features/databases/model_test.go so the copy test covers it; verify with just test-package ./internal/features/databases/... in backend/
  • 1.2 Make the dump-scope matcher agree with pg_dump for unqualified entries: run RESET search_path before the size and privilege queries, select pg_catalog.pg_table_is_visible(c.oid) in both, carry it on relationName, require it in isMatchingRelation for a pattern without a schema part, and correct the comment at dumpscope.go:80. Add a size test in postgresql/logical/model_test.go where logs is excluded and a same-named table in a second schema is still counted, and a per-version case in privileges_test.go where logs is excluded and an unreadable same-named table in a second schema makes the connection test fail with its name; verify with just test-package ./internal/features/databases/databases/postgresql/logical/... in backend/
  • 1.3 Add ExcludeTableDataPatterns to DumpFilter with a normalizing getter beside getExcludeTablePatterns, pass ExcludeTableData into both DumpFilter literals in model.go, and make getDumpedRelationsSizeBytes skip a relation matched by either list. Add Test_GetRawDbSizeMb_WhenExcludeTableDataSet_SkipsTableSize beside the existing exclude-tables size tests in postgresql/logical/model_test.go, asserting that the estimate drops by at least the table's total relation size, indexes included; verify with just test-package ./internal/features/databases/databases/postgresql/logical/... in backend/
  • 1.4 Keep the privilege check skipping only whole-excluded relations, and change the missing-privileges message in privileges.go to suggest include schemas and whole-table exclusion and to state that excluding only a table's data still requires SELECT on it. Add a per-version case in privileges_test.go beside testConnectionUnreadableTableExcluded where the unreadable table is listed in the data-excluded list and the connection test fails with an error naming that table and mentioning the data-exclusion note; verify with just test-package ./internal/features/databases/databases/postgresql/logical/... in backend/
  • 1.5 Append --exclude-table-data=<entry> for every normalized entry of ExcludeTableData after the --exclude-table arguments in buildPgDumpArgs. Add a unit test in create_backup_uc_test.go that both lists produce their flags in that order with unnormalized input trimmed and deduplicated; verify with just test-package ./internal/features/backups/backups/usecases/logical/postgresql/... in backend/
  • 1.6 Add backup-to-restore subtests in backend/internal/features/tests/logical/postgresql/backup_restore_test.go, run for every version like Test_BackupAndRestorePostgresql_WithExcludeTables_ExcludedTablesNotRestored: a table listed in the data-excluded list, with rows, a primary key and a secondary index, is restored with both indexes and zero rows while a neighbour keeps its rows, and the backup's raw size leaves the emptied table out; the pattern *.history_* empties matching tables in two schemas, while the unqualified logs empties public.logs and leaves a same-named table in a second schema with its rows; the unqualified whole-excluded audit_tmp removes public.audit_tmp and keeps a same-named table in a second schema; a partitioned table named alone in the data-excluded list is restored with its partitions' rows, and the same partitions matched by a pattern are restored empty; with the backup limited to the public schema, a data-excluded logs leaves public.logs empty and the restore has no reporting schema; a table listed in both lists is not restored at all; verify with just test-package ./internal/features/tests/logical/postgresql/... in backend/

2. Frontend

  • 2.1 Add excludeTableData?: string[] to PostgresqlLogicalDatabase.ts. Add databases.fields.excludeWholeTables, databases.fields.excludeTableData, databases.edit.postgresql.excludeTableDataTooltip and databases.edit.postgresql.excludeTableDataPlaceholder to all six dictionaries, and rewrite databases.edit.postgresql.excludeTablesTooltip in all six, with the tooltip content the spec requires and each language written per the translation rules in website/AGENTS.md; verify with pnpm test (the dictionary placeholder test) and pnpm typecheck in frontend/
  • 2.2 In EditPostgreSqlLogicalSpecificDataComponent.tsx, switch the whole-table row to the excludeWholeTables label, add the "Exclude table data" row directly below it with the same markup, normalization and restore-mode hiding, and include excludeTableData in the condition that opens Advanced settings. Add EditPostgreSqlLogicalSpecificDataComponent.test.tsx rendering with renderToStaticMarkup, following EditTelegramNotifierComponent.test.tsx: a database whose only advanced value is a data-excluded table renders both labels in order with the entry, and a database with no advanced values renders neither. Add EditMySqlSpecificDataComponent.test.tsx rendering a MySQL database with an excluded table the same way and checking the label is still "Exclude tables"; verify with pnpm test in frontend/
  • 2.3 In ShowPostgreSqlLogicalSpecificDataComponent.tsx, show the whole-table list under excludeWholeTables and the data-excluded list under excludeTableData when each is not empty. Add ShowPostgreSqlLogicalSpecificDataComponent.test.tsx checking that each list renders under its label when set and is absent otherwise; verify with pnpm test in frontend/

3. Final checks

  • 3.1 Run just format and just lint at the repository root and pnpm build in frontend/, and fix every finding in the touched files; verify all three exit cleanly