backup

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package backup writes database dumps, docker volumes, and the panel's own SQLite file to S3-compatible destinations, restores from them, prunes old archives, and runs the schedules that trigger all of it.

Every archive is spooled to a local scratch file before it is uploaded. That is what makes the volume modes work: the container is only frozen for the length of the local tar, never for the length of the upload. It also gives restore something to verify before it wipes anything.

Index

Constants

View Source
const (
	RunKind     = "backup.run"
	RestoreKind = "backup.restore"
)

Work-queue kinds.

Variables

This section is empty.

Functions

func OrgOf

func OrgOf(ctx context.Context, store repo.Store, t *repo.Tile) (string, error)

OrgOf returns the org that owns a tile.

func ParseRef

func ParseRef(s string) (scope, name string, ok bool)

ParseRef reads a destination reference, ${{ org.backups.NAME }} or ${{ stackr.backups.NAME }}, into its scope and name. ok is false for anything that is not a reference, which the caller then treats as a destination id.

func ResolveDestination

func ResolveDestination(ctx context.Context, store repo.Store, orgID, destID string) (*repo.BackupDestination, error)

ResolveDestination loads a destination and refuses it unless the caller's org may use it: its own, or an admin-global one the admin has marked shared.

This is the check a route-level "tile → org → membership" pass does not make. The tile genuinely belongs to the caller's org; the destination is what crosses the tenant boundary, and it carries the credentials the archive is written with. Both the web handlers and the v1 API go through here.

func ResolveNamed

func ResolveNamed(ctx context.Context, store repo.Store, orgID, scope, name string) (*repo.BackupDestination, error)

ResolveNamed finds the destination a config file's `dest:` reference points at. scope is "org" for ${{ org.backups.NAME }} and "stackr" for ${{ stackr.backups.NAME }}.

Names, not ids: the file is in git and shared across environments, and a destination id means nothing to a person reading it. Two destinations with the same name in reach is an error rather than a coin flip.

func TestDestination

func TestDestination(ctx context.Context, d *repo.BackupDestination) error

TestDestination verifies a destination by writing and deleting a probe.

func ValidMode

func ValidMode(m string) bool

ValidMode reports whether m is one of the three container modes.

func Validate

func Validate(b *repo.Backup) error

Validate checks a backup config before it is saved: known kind, known mode, parseable schedule, sane retention.

func VolumeFor

func VolumeFor(t *repo.Tile) (string, error)

VolumeFor resolves the docker volume a tile's data lives in. A service tile has none of its own, its data sits in the volume tiles attached to it, and those are what carry the backup config.

Types

type Service

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

func NewService

func NewService(store repo.Store, dbs *managedtiles.Service, c *cluster.Cluster, db *sqlx.DB, dataDir, version string) *Service

func (*Service) LatestRestore added in v0.4.0

func (s *Service) LatestRestore(ctx context.Context, backupID string) (*repo.WorkItem, error)

LatestRestore is the newest restore of a backup, nil when there has been none. The page and the CLI read a restore's state from here.

func (*Service) LoadSchedules

func (s *Service) LoadSchedules(ctx context.Context) error

LoadSchedules (re)registers cron entries for every enabled backup. Call it at startup and after any change to a schedule.

func (*Service) Start added in v0.4.0

func (s *Service) Start(ctx context.Context, backupID, trigger string) (*repo.BackupRun, error)

Start queues one backup and returns its run row, already written so the history can show it waiting. trigger is "schedule" or "manual".

func (*Service) StartRestore added in v0.4.0

func (s *Service) StartRestore(ctx context.Context, backupID, runID string) (string, error)

StartRestore queues a restore of one run and returns the work item id. The checks that can fail at once are made here, so the button answers.

func (*Service) WithWork added in v0.4.0

func (s *Service) WithWork(q *workqueue.Queue) *Service

WithWork registers both kinds. Call before the queue starts, or boot recovery finds no handler for an interrupted backup.

func (*Service) WritePanelArchiveTo added in v0.1.1

func (s *Service) WritePanelArchiveTo(p string) error

WritePanelArchiveTo writes the panel archive to a local file. It lands under a temporary name first, so a failed write never leaves a truncated archive that looks restorable.

Jump to

Keyboard shortcuts

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