How greenmaskio/greenmask works
Greenmask is a PostgreSQL logical-backup and data-anonymization utility. Its main workflow is to select database objects, optionally subset related rows, apply configured transformations while dumping, store the resulting backup, and later restore it. The CLI also exposes validation and dump/transformer management. The README documents additional transformation features and storage options; sampled source confirms runtime-context construction and row transformation, but not every command’s internal wiring, so uncertain links are omitted.
Main entry points: dump.go Postgres dump · context.go Runtime context · root.go Command router · storager.go Storage interface
Components 28
CLI commands
- Command router
cmd/greenmask/cmd/root.go - Dump command
cmd/greenmask/cmd/dump/dump.go - Restore command
cmd/greenmask/cmd/restore/restore.go - Validate command
cmd/greenmask/cmd/validate/validate.go - Dump management
cmd/greenmask/cmd/list_dumps/list_dumps.go
PostgreSQL runtime
- Postgres dump
internal/db/postgres/cmd/dump.go - Runtime context
internal/db/postgres/context/context.go - Subset planner
internal/db/postgres/subset/query.go - Entry producer
internal/db/postgres/entries/entry_producer.go - Dump pipeline
internal/db/postgres/dumpers/dumpers.go - COPY encoding
internal/db/postgres/pgcopy/encoder.go - Postgres restore
internal/db/postgres/cmd/restore.go
Transformation engine
- Row transformations
internal/db/postgres/dumpers/transformation_pipeline.go - Transformer library
internal/db/postgres/transformers/masking.go - Transformer registry
internal/db/postgres/transformers/utils/registry.go - Value generators
internal/generators/generator.go
Backup storage
- Storage interface
internal/storages/storager.go - Storage selection
internal/storages/builder/builder.go - Directory backend
internal/storages/directory/directory.go - S3 backend
internal/storages/s3/s3.go - Azure backend
internal/storages/azure/azure.go - SFTP backend
internal/storages/ssh/ssh.go - Backup objects
internal/storages/domains/domains.go
Shared data model
- Typed records
pkg/toolkit/record.go - Schema model
pkg/toolkit/database_schema.go
Other components
- Operator
- PostgreSQL
- Storage target
Connections 32
- Operator → Command router: invokes
- Command router → Dump command: dispatches
- Command router → Restore command: dispatches
- Command router → Validate command: dispatches
- Command router → Dump management: dispatches
- Dump command → Postgres dump: runs dump
- Validate command → Runtime context: builds validation context
- Postgres dump → Runtime context: builds runtime
- Runtime context → PostgreSQL: introspects schema
- Runtime context → Subset planner: plans subset queries
- Runtime context → Entry producer: collects dump entries
- Entry producer → PostgreSQL: reads database objects
- Dump pipeline → COPY encoding: encodes rows
- Row transformations → Typed records: decodes and encodes
- Row transformations → Transformer library: applies transforms
- Transformer library → Value generators: generates values
- Runtime context → Transformer registry: uses transformer definitions
- Postgres dump → Dump pipeline: streams dump data
- Postgres dump → Row transformations: transforms table rows
- Postgres dump → Storage selection: selects storage
- Storage selection → Storage interface: creates backend
- Storage interface → Directory backend: implemented by
- Storage interface → S3 backend: implemented by
- Storage interface → Azure backend: implemented by
- Storage interface → SFTP backend: implemented by
- Postgres dump → Backup objects: writes backup metadata
- Postgres dump → Storage target: stores backup
- Storage target → Backup objects: holds objects
- Restore command → Postgres restore: runs restore
- Postgres restore → Storage selection: selects storage
- Postgres restore → PostgreSQL: restores objects
- Runtime context → Schema model: builds schema view