backup

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package backup creates integrity-checked, portable snapshots without copying live WAL files.

On SQLite a snapshot holds a VACUUM INTO copy (ether.db). On PostgreSQL, where file copies do not apply, it holds a logical dump of every table (database.jsonl, see store.ExportLogical) and the manifest records dialect "postgres"; a restored dump is imported into an empty database on the next start (ImportPending).

Index

Constants

View Source
const LogicalDumpFile = "database.jsonl"

LogicalDumpFile is the PostgreSQL bundle's database entry. Left in a data directory by a restore, it is imported into the (empty) database at start.

Variables

This section is empty.

Functions

func FilesystemWarning

func FilesystemWarning(ctx context.Context, dataDir string) string

FilesystemWarning detects the mount containing dataDir on Linux and macOS.

func ImportPending

func ImportPending(ctx context.Context, db *sql.DB, dataDir string) (bool, error)

ImportPending imports a restored logical dump (LogicalDumpFile in dataDir) into db, which must be freshly migrated and empty, then renames the dump so it is imported only once. It reports whether it imported.

func RestoreBundle

func RestoreBundle(ctx context.Context, r io.Reader, destination string) error

RestoreBundle validates all content before atomically installing into a new directory. It deliberately refuses existing destinations and never replaces a running database.

Types

type Manifest

type Manifest struct {
	Version int               `json:"version"`
	Created time.Time         `json:"created"`
	SHA256  map[string]string `json:"sha256"`
	// Dialect is "postgres" for a logical dump; empty means SQLite.
	Dialect string `json:"dialect,omitempty"`
}

type Node

type Node struct {
	ID, Name string
}

Node identifies the cluster node a Service runs on.

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(db *sql.DB, configPath, dir string, retain int) *Service

func (*Service) Configure

func (s *Service) Configure(ctx context.Context, v Settings) error

func (*Service) Create

func (s *Service) Create(ctx context.Context) (Snapshot, error)

func (*Service) Handler

func (s *Service) Handler() http.Handler

func (*Service) List

func (s *Service) List() ([]Snapshot, error)

List is this node's own bundles (its data directory's backups).

func (*Service) Run

func (s *Service) Run(ctx context.Context, onError func(error))

func (*Service) SetCluster

func (s *Service) SetCluster(n Node)

SetCluster marks the server as clustered: every bundle is recorded in the shared database with the node that holds it (so any node lists the whole cluster's backups), and the shared backup directory setting is honoured. A standalone server never calls it and keeps its bundles in its data directory only.

func (*Service) Settings

func (s *Service) Settings(ctx context.Context) (Settings, error)

func (*Service) Snapshots

func (s *Service) Snapshots(ctx context.Context) ([]Snapshot, error)

Snapshots lists backups for the owner: this node's bundles on a standalone server, every node's (with where each is) on a clustered one.

type Settings

type Settings struct {
	IntervalHours int   `json:"intervalHours"`
	Retain        int   `json:"retain"`
	LastRun       int64 `json:"lastRun"`
	// SharedDir (clustered servers) is a directory every node can reach,
	// at the same path, where scheduled and manual backups are written
	// instead of the writing node's data directory. Empty keeps them on
	// the node that made them.
	SharedDir string `json:"sharedDir,omitempty"`
}

type Snapshot

type Snapshot struct {
	Name    string    `json:"name"`
	Size    int64     `json:"size"`
	Created time.Time `json:"created"`
	// Clustered servers only: the node that wrote the bundle and holds it
	// (unless Shared), whether it is in the shared backup directory, and
	// Remote when it is on another node's disk (download it there).
	Node   string `json:"node,omitempty"`
	NodeID string `json:"nodeId,omitempty"`
	Shared bool   `json:"shared,omitempty"`
	Remote bool   `json:"remote,omitempty"`
}

Jump to

Keyboard shortcuts

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