backup

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package backup owns the shared Rustic backup engine used by volume and system backups: typed repository operations, per-repository serialization through the actor runtime, and run admission.

Index

Constants

View Source
const (
	VolumeAdmissionScope = "volume-backup"
	SystemAdmissionScope = "system-backup"
)

Admission scopes shared by the backup engine and the per-policy job registries so scheduled and manual runs contend on the same leases.

Variables

This section is empty.

Functions

func ExpiredRunIDs

func ExpiredRunIDs(ctx context.Context, db *database.DB, table, policyID string, keep int) ([]string, error)

ExpiredRunIDs returns the IDs of succeeded runs with snapshots that fall outside the newest keep entries for one policy, oldest last. Callers delete each run through their own delete path so snapshots are forgotten too.

func ValidatePolicyUpdate added in v2.10.0

ValidatePolicyUpdate applies the shared cron, retention, and destination rules used by backup policies.

Types

type DiscoveredSnapshot

type DiscoveredSnapshot struct {
	ID      string    `json:"id"`
	Time    time.Time `json:"time"`
	Summary struct {
		TotalBytesProcessed int64 `json:"total_bytes_processed"`
	} `json:"summary"`
}

DiscoveredSnapshot describes one snapshot found in a repository.

type Engine

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

Engine executes typed Rustic operations through the official Rustic image. Concurrency is actor-owned: one executor per repository ID plus the shared application admission gate for run exclusivity.

func NewEngine

func NewEngine(ctx context.Context, runtime *actors.Runtime, admission *actors.Gate[actors.AdmissionKey], imageService *image.ImageService) *Engine

NewEngine creates the shared backup engine on the actor runtime. ctx is the application lifecycle context repository executors are spawned on.

func (*Engine) CreateSnapshot

func (e *Engine) CreateSnapshot(ctx context.Context, dockerClient *client.Client, repository Repository, password, label string, source mount.Mount) (Snapshot, error)

CreateSnapshot backs the source mount up into the repository and returns the created snapshot. The repository is initialized on first use.

func (*Engine) ForgetSnapshots added in v2.10.0

func (e *Engine) ForgetSnapshots(ctx context.Context, dockerClient *client.Client, repository Repository, password string, snapshotIDs []string) error

ForgetSnapshots removes the snapshots from the repository and prunes their data in a single pass.

func (*Engine) ListSnapshotFiles

func (e *Engine) ListSnapshotFiles(ctx context.Context, dockerClient *client.Client, repository Repository, password, snapshotID, filePath string, recursive bool) ([]string, error)

ListSnapshotFiles lists a snapshot path and returns paths relative to the snapshot root. A supplied path is nonrecursive unless recursive is true.

func (*Engine) ListSnapshots

func (e *Engine) ListSnapshots(ctx context.Context, dockerClient *client.Client, repository Repository, password string) ([]DiscoveredSnapshot, error)

ListSnapshots enumerates every snapshot in the repository.

func (*Engine) ReadSnapshotTextFile added in v2.10.0

func (e *Engine) ReadSnapshotTextFile(ctx context.Context, dockerClient *client.Client, repository Repository, password, snapshotID, filePath string) (string, error)

ReadSnapshotTextFile returns one text file from a snapshot.

func (*Engine) Replicate

func (e *Engine) Replicate(ctx context.Context, dockerClient *client.Client, from Repository, fromSnapshotID string, to Repository, password, label string) (Snapshot, error)

Replicate copies one snapshot between repositories by restoring it into a temporary volume and backing that volume up into the target repository. The source is read once from the repository, never from the live data. Rustic's native `copy` would move only missing packs, but it addresses the target via a TOML config profile, which the env-only Repository cannot express yet — the materialize-and-rebackup here trades disk and I/O for that simplicity.

func (*Engine) RestoreSnapshot

func (e *Engine) RestoreSnapshot(ctx context.Context, dockerClient *client.Client, repository Repository, password, snapshotID string, target mount.Mount, options RestoreOptions) error

RestoreSnapshot restores a snapshot (or one path inside it) onto the target mount.

func (*Engine) Stop

func (e *Engine) Stop(ctx context.Context) error

Stop cancels and joins backup runs before stopping their repository executors.

func (*Engine) SubmitRun added in v2.10.2

func (e *Engine) SubmitRun(ctx context.Context, id string, work func(context.Context) error, after func(error)) error

SubmitRun accepts one backup on an executor independent of repository work. after owns finalization only when submission succeeds.

func (*Engine) TryAcquireRun

func (e *Engine) TryAcquireRun(ctx context.Context, scope, id string) (*actors.Lease[actors.AdmissionKey], bool, error)

TryAcquireRun admits at most one in-flight backup run per (scope, id), shared between scheduled jobs and manual API triggers.

type PolicyReconciliation

type PolicyReconciliation[P, U any] struct {
	// Domain names the backup flavor in validation errors ("volume", "system").
	Domain string
	DB     *database.DB
	// Existing is every policy currently persisted for the reconciled scope.
	Existing []P
	ID       func(*P) string
	UpdateID func(U) string
	// New returns the blank policy for created entries, pre-scoped by the
	// caller (e.g. with the volume name set).
	New func() P
	// Build validates an update and applies it to an existing or new policy.
	Build func(ctx context.Context, policy *P, update U) error
	// Persist overrides the default GORM transaction for settings-backed policies.
	Persist    func(ctx context.Context, policies []P) error
	Unregister func(ctx context.Context, policyID string)
	Reschedule func(ctx context.Context, policy *P)
}

PolicyReconciliation reconciles a full set of policy updates against the existing policies of one backup domain, then swaps the scheduled jobs.

func (PolicyReconciliation[P, U]) Run

func (r PolicyReconciliation[P, U]) Run(ctx context.Context, updates []U) error

type Repository

type Repository struct {
	ID          string
	Environment []string
	Mounts      []mount.Mount
}

Repository addresses one Rustic repository. ID is the stable serialization key: operations against the same ID run serially, different IDs concurrently.

type RestoreOptions

type RestoreOptions struct {
	// DeleteExtra removes files in the target that are absent from the snapshot.
	DeleteExtra bool
	// SourcePath restores only this path inside the snapshot when non-empty.
	SourcePath string
	// DestinationPath overrides the restore target path inside the helper
	// container; the target mount's path is used when empty.
	DestinationPath string
}

RestoreOptions selects what a snapshot restore writes and where.

type Snapshot

type Snapshot struct {
	ID   string `json:"id"`
	Size int64  `json:"-"`
}

Snapshot is the result of a completed Rustic backup operation.

Jump to

Keyboard shortcuts

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