backup

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 28 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

This section is empty.

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) 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) Restore

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

Restore puts one recorded run back. The run is loaded by id and must belong to this backup, the object key is never taken from the caller, because on a shared bucket that would be a cross-tenant read.

Volume restores are destructive and ordered so that every recoverable failure happens before the wipe: take a pre-restore backup, download, verify, and only then stop → wipe → extract → start.

func (*Service) Run

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

Run executes one backup end to end: produce the archive locally, upload it, prune what falls outside the keep count. trigger is recorded on the run row ("schedule", "manual", or "pre-restore").

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