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
- func OrgOf(ctx context.Context, store repo.Store, t *repo.Tile) (string, error)
- func ParseRef(s string) (scope, name string, ok bool)
- func ResolveDestination(ctx context.Context, store repo.Store, orgID, destID string) (*repo.BackupDestination, error)
- func ResolveNamed(ctx context.Context, store repo.Store, orgID, scope, name string) (*repo.BackupDestination, error)
- func TestDestination(ctx context.Context, d *repo.BackupDestination) error
- func ValidMode(m string) bool
- func Validate(b *repo.Backup) error
- func VolumeFor(t *repo.Tile) (string, error)
- type Service
- func (s *Service) LatestRestore(ctx context.Context, backupID string) (*repo.WorkItem, error)
- func (s *Service) LoadSchedules(ctx context.Context) error
- func (s *Service) Start(ctx context.Context, backupID, trigger string) (*repo.BackupRun, error)
- func (s *Service) StartRestore(ctx context.Context, backupID, runID string) (string, error)
- func (s *Service) WithWork(q *workqueue.Queue) *Service
- func (s *Service) WritePanelArchiveTo(p string) error
Constants ¶
const ( RunKind = "backup.run" RestoreKind = "backup.restore" )
Work-queue kinds.
Variables ¶
This section is empty.
Functions ¶
func ParseRef ¶
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.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) LatestRestore ¶ added in v0.4.0
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 ¶
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
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
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
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
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.