dbbackup

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanSpool

func CleanSpool(cfg dbspec.Config) error

CleanSpool removes leftovers of earlier runs (no run is in flight at agent start)

func IsPrecheck

func IsPrecheck(err error) bool

IsPrecheck reports whether err is (or wraps) a PrecheckError

func Run

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

func (Binary) String

func (b Binary) String() string

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

type DetectResult struct {
	Engine string
	Tools  ToolInfo
	Err    error
}

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

func Lookup

func Lookup(name string) (Engine, bool)

Lookup returns the engine for a canonical engine name

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

type PrecheckError struct {
	Msg  string
	Hint string
	Err  error
}

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

func (Progress) Describe

func (p Progress) Describe() string

Describe renders the progress for heartbeats

type ProgressFunc

type ProgressFunc func(Progress)

ProgressFunc receives progress updates

type Result

type Result struct {
	ExitCode int
	Stderr   string
	Duration time.Duration
}

Result describes a finished command

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

func NewRunner

func NewRunner(killGrace time.Duration) Runner

NewRunner returns the process runner used by the agent

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

func (*ToolError) Error

func (e *ToolError) Error() string

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

func (ToolInfo) Manifest

func (t ToolInfo) Manifest() map[string]dbspec.Tool

Manifest converts the detected tools for the manifest

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL