Documentation
¶
Index ¶
- func BuildCommands(outDir string, commandBuilder CommandBuilder, targets Targets, dump bool) ([]string, error)
- func DumpCommand(t Target) string
- func FilterInvalidLines(dst io.Writer, src io.ReadSeeker, progressFn func(int64)) (int64, error)
- func RestoreCommand(t Target) string
- type CommandBuilder
- type Output
- type PGCommand
- type Target
- type Targets
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildCommands ¶
func BuildCommands(outDir string, commandBuilder CommandBuilder, targets Targets, dump bool) ([]string, error)
BuildCommands generates commands that output Postgres dumps and sends them to predefined files for each target database.
func DumpCommand ¶
DumpCommand generates a pg_dump command that can be used for on-prem-to-Cloud migrations.
func FilterInvalidLines ¶
FilterInvalidLines copies the initial lines of the pg_dump-created .sql files, from src to dst (the GCS bucket), until it hits a line prefixed with a filterEndMarker, while commenting out the linesToFilter which cause `gcloud sql import` to error out. It then resets src to the position of the last contents written to dst.
Filtering requires reading entire lines into memory, this can be a very expensive operation, so when filtering is complete, the more efficient io.Copy is used to perform the remainder of the copy in the calling funciton
pg_dump writes these .sql files based on its own version, not based on the Postgres version of either the source or destination database; so self-hosted customers' diverse database environments have inserted a variety of statements into the .sql files which cause the import to fail For details, see https://cloud.google.com/sql/docs/postgres/import-export/import-export-dmp
func RestoreCommand ¶
RestoreCommand generates a psql command that can be used for migrations.
Types ¶
type CommandBuilder ¶
type Target ¶
type Target struct {
// Target is the DSN of the database deployment:
//
// - in docker, the name of the database container, e.g. pgsql, codeintel-db, codeinsights-db
// - in k8s, the name of the deployment or statefulset, e.g. deploy/pgsql, sts/pgsql
// - in plain pg_dump, the server host or socket directory
Target string `yaml:"target"`
DBName string `yaml:"dbname"`
Username string `yaml:"username"`
// Only include password if non-sensitive
Password string `yaml:"password"`
}
Target represents a database for pg_dump to export.