backup

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package backup produces and manages the pre-migrated database dump shared by every worktree of a project.

Index

Constants

View Source
const (

	// RestoreScriptName is the docker-entrypoint-initdb.d script each worktree
	// reaches through its .db-snapshot link.
	RestoreScriptName = "restore-snapshot.sh"
)

Variables

This section is empty.

Functions

func DumpPath added in v0.17.1

func DumpPath(root, name string) string

DumpPath is for the readers holding a backups root and no Manager.

func ProjectDir added in v0.10.0

func ProjectDir(root, name string) (string, error)

ProjectDir is where a project's dump, its meta and the restore script live. It is 0755 under a 0700 root on purpose: the database container mounts this very directory and runs the restore as its own user, never as root.

Types

type Info

type Info struct {
	Name    string
	Present bool
	Size    int64
	Meta    Meta
}

type Manager

type Manager struct {
	Runner          execx.Runner
	Root            string
	Out             io.Writer
	MaxWaitAttempts int
}

func (*Manager) Check

func (m *Manager) Check(ctx context.Context, name string, p config.Project) Staleness

func (*Manager) DumpPath

func (m *Manager) DumpPath(name string) string

func (*Manager) List

func (m *Manager) List(cfg *config.Config) ([]Info, error)

List reports every project that has, or is expected to have, a backup.

func (*Manager) MetaPath

func (m *Manager) MetaPath(name string) string

func (*Manager) ReadMeta

func (m *Manager) ReadMeta(name string) (Meta, error)

func (*Manager) Refresh

func (m *Manager) Refresh(ctx context.Context, name string, p config.Project) error

Refresh regenerates the dump: it starts the database if needed, migrates a throwaway one and dumps it as migrate left it. What the migrations create is captured, permissions and reference data included; seed data is not.

func (*Manager) Remove

func (m *Manager) Remove(name string) (bool, error)

Remove deletes the dump and its metadata. Removing an absent backup is not an error; the boolean says whether anything was actually deleted.

type Meta

type Meta struct {
	GeneratedAt time.Time `json:"generated_at"`
	GitRev      string    `json:"git_rev"`
}

Meta travels next to the dump so `backup list` can say how old it is.

type Staleness

type Staleness struct {
	Commits int  // commits touching migrations since the dump was taken
	Known   bool // false when the recorded revision cannot be compared
}

Staleness says how far a dump has fallen behind the migrations it was built from. A stale dump still works, the application simply replays the delta on startup, so this is worth reporting and never worth blocking on.

func (Staleness) Behind

func (s Staleness) Behind() bool

func (Staleness) Describe

func (s Staleness) Describe() string

Jump to

Keyboard shortcuts

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