Documentation
¶
Overview ¶
Package dbbackup executes database backups on fallbck-db-agent: it detects the client tools, checks the server, dumps into a spool directory, writes the manifest and hands the spool to the pxar upload engine.
Index ¶
- func CleanSpool(cfg dbspec.Config) error
- func IsPrecheck(err error) bool
- func Run(ctx context.Context, o RunOptions) (*temporal.BackupExecutionResult, error)
- type Binary
- type Command
- type DetectResult
- type DumpRequest
- type Engine
- type EngineResult
- type PrecheckError
- type Progress
- type ProgressFunc
- type Result
- type RunOptions
- type Runner
- type ServerInfo
- type ToolError
- type ToolInfo
- type UploadFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanSpool ¶
CleanSpool removes leftovers of earlier runs (no run is in flight at agent start)
func IsPrecheck ¶
IsPrecheck reports whether err is (or wraps) a PrecheckError
func Run ¶
func Run(ctx context.Context, o RunOptions) (*temporal.BackupExecutionResult, error)
Run executes one database backup run end to end
Types ¶
type Binary ¶
type Binary struct {
Path string
Version string
Major int
Minor int
Patch int
// Flavor distinguishes mysql/mariadb tools
Flavor string
}
Binary is a detected client tool
type Command ¶
type Command struct {
// Name is the logical tool name for logs and errors
Name string
Path string
Args []string
Env []string
Dir string
Stdout io.Writer
}
Command describes a client tool invocation. Env is the complete environment (the agent's own environment, which carries its token, is never inherited).
type DetectResult ¶
DetectResult is one line of `fallbck-db-agent tools`
func DetectAll ¶
func DetectAll(ctx context.Context, r Runner, tools dbspec.ToolConfig) []DetectResult
DetectAll runs Detect for every engine (diagnostics)
func (DetectResult) Format ¶
func (d DetectResult) Format() string
Format renders a DetectResult for humans
type DumpRequest ¶
type DumpRequest struct {
RunID string
JobID string
Label string
Spec *dbspec.Spec
Creds dbspec.Credentials
Tools ToolInfo
// Server is filled by Precheck
Server ServerInfo
// Databases is the resolved list to dump (filled by Precheck; nil = all-in-one dump)
Databases []string
// SpoolDir exists and is empty on entry; SecretDir (0700) holds credential files
SpoolDir string
SecretDir string
// PrevState is the last successful run's state (nil on the first run)
PrevState *dbspec.JobState
Progress ProgressFunc
Runner Runner
}
DumpRequest carries everything an engine needs for one run
type Engine ¶
type Engine interface {
Name() string
// Detect finds the client binaries and their versions; it never contacts a server
Detect(ctx context.Context, r Runner, tools dbspec.ToolConfig) (ToolInfo, error)
// Precheck connects to the server and verifies versions, privileges and options
// the dump would otherwise fail on late; configuration problems are *PrecheckError
Precheck(ctx context.Context, req *DumpRequest) (ServerInfo, error)
// Dump writes everything for this run under req.SpoolDir
Dump(ctx context.Context, req *DumpRequest) (*EngineResult, error)
}
Engine is one database family
type EngineResult ¶
type EngineResult struct {
ConsistentAsOf time.Time
Databases []dbspec.DatabaseEntry
Warnings []string
Notes []string
Postgres *dbspec.PostgresManifest
MySQL *dbspec.MySQLManifest
MongoDB *dbspec.MongoManifest
Restore dbspec.Restore
// State is the engine part of the job state saved after a successful upload
State *dbspec.JobStateRecord
}
EngineResult is the engine-specific outcome of Dump
type PrecheckError ¶
PrecheckError is a configuration or environment problem that a retry will not fix
func (*PrecheckError) Error ¶
func (e *PrecheckError) Error() string
func (*PrecheckError) Unwrap ¶
func (e *PrecheckError) Unwrap() error
type Progress ¶
type Progress struct {
// Phase: detect, precheck, dump, basebackup, binlog, manifest, upload
Phase string
// Current names the database/file being processed
Current string
BytesInSpool int64
}
Progress is reported while a run executes
type RunOptions ¶
type RunOptions struct {
Session *temporal.BackupSessionInfo
Spec *dbspec.Spec
// Password is the server-stored job password ("" = resolve from an agent profile)
Password string
Config dbspec.Config
Upload UploadFunc
Progress ProgressFunc
// Runner overrides the process runner (tests)
Runner Runner
Hostname string
AgentVersion string
// PollInterval overrides the spool poll interval (tests)
PollInterval time.Duration
}
RunOptions parameterise Run
type Runner ¶
type Runner interface {
Run(ctx context.Context, c Command) (Result, error)
LookPath(name string) (string, error)
}
Runner executes client tools; tests substitute a fake
type ServerInfo ¶
type ServerInfo struct {
Version string
VersionNum int
Flavor string
IsReplica bool
// EstimatedBytes of the dump (0 = unknown)
EstimatedBytes int64
// Superuser reports whether the backup role is a superuser (PostgreSQL)
Superuser bool
// Attrs carries engine-specific server facts needed by Dump (binlog state, gtid mode)
Attrs map[string]string
Notes []string
}
ServerInfo is the result of Engine.Precheck
type ToolError ¶
type ToolError struct {
Tool string
ExitCode int
Stderr string
// Hint explains known failure messages; Config marks configuration problems
Hint string
Config bool
}
ToolError is a non-zero exit of a client tool
type ToolInfo ¶
type ToolInfo struct {
// Binaries by logical name (pg_dump, pg_dumpall, pg_basebackup; dump, binlog; mongodump)
Binaries map[string]Binary
// Alternatives are complete tool sets found in other well-known directories
// (several PostgreSQL majors installed side by side); Precheck may switch to one
Alternatives []map[string]Binary
}
ToolInfo is the result of Engine.Detect
type UploadFunc ¶
type UploadFunc func(ctx context.Context, spoolDir string, blobs []gopbs.Blob, progress func(archive string, stats pbs.UploadStats, done bool)) (*temporal.BackupExecutionResult, error)
UploadFunc uploads the spool directory (as the archive) plus blobs to PBS; the activity binds it to the pxar engine with the run's session.