Documentation
¶
Overview ¶
Package dbbackup executes database backups on fallbck-agent (and, through the db-worker mode, inside kubernetes dump pods): 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 FreeBytes(path string) uint64
- 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 FileStateStore
- type MemoryStateStore
- type PrecheckError
- type Progress
- type ProgressFunc
- type Result
- type RunOptions
- type Runner
- type ServerInfo
- type ServerVersion
- type StateStore
- 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 FreeBytes ¶ added in v0.12.0
FreeBytes reports the free space on the filesystem holding path (0 when unknown)
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-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
// Snapshot is the PBS snapshot this run writes (type/id/time); engines that keep
// a chain record it so later runs can point back at it
Snapshot 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
MSSQL *dbspec.MSSQLManifest
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 FileStateStore ¶ added in v0.9.5
type FileStateStore struct{ Dir string }
FileStateStore keeps <dir>/<jobID>.json; an empty dir disables persistence
type MemoryStateStore ¶ added in v0.9.5
MemoryStateStore holds the previous state supplied by the caller and captures the state a run wants saved (worker pods hand it back in their termination message)
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
// State overrides where the job's chain state is read and written (default: JSON
// files under Config.StateDir)
State StateStore
// Generator names the agent in the manifest (default fallbck-agent)
Generator string
}
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 ServerVersion ¶ added in v0.9.5
ServerVersion is the minimum a caller needs to pick matching client tools before a run: the kubernetes agent uses it to choose the dump pod's image tag.
func ProbeServerVersion ¶ added in v0.9.5
func ProbeServerVersion(ctx context.Context, spec *dbspec.Spec, creds dbspec.Credentials) (ServerVersion, error)
ProbeServerVersion connects with the run's credentials and reads the server version. MongoDB is not supported (the agent carries no driver): the caller falls back to its default image.
type StateStore ¶ added in v0.9.5
type StateStore interface {
// Load returns the job state or nil when none exists
Load(ctx context.Context, jobID string) (*dbspec.JobState, error)
Save(ctx context.Context, jobID string, st *dbspec.JobState) error
}
StateStore persists the per-job chain state (last binlog position, WAL LSN) between runs. The db agent keeps one JSON file per job; the kubernetes worker pod is ephemeral and receives/returns the state through the agent instead.
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) (*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.