restore

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package restore puts a backup in place and makes the farm safe to resume from it: every attempt the restored database still records as open is handed back (the fence), and the JetStream state, whose messages belong to a different moment, is moved aside (the embedded broker's directory) or purged (an external broker). See docs/operations.md, Restore.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSQIBackup = errors.New("restore: not an sqi backup")

ErrNotSQIBackup means the file is not a database or archive sqi wrote.

Functions

func Fence

func Fence(ctx context.Context, st store.Store, now time.Time) (int, error)

Fence hands back every open attempt as a worker shutdown does: the task returns to ready, the attempt closes as failed (worker shutdown), its claims are released, and no retry or job failure is counted. It returns how many it reclaimed. It must run with the single-server lock held, so nothing can open an attempt meanwhile; it fails if any attempt is still open afterwards.

Types

type Options

type Options struct {
	Driver      string // backend.DriverSQLite (also "") or backend.DriverPostgres
	SQLitePath  string
	PostgresDSN string
	NATSDataDir string // "" skips the quarantine
	Backup      string // the backup to restore; "" with InPlace
	InPlace     bool
	Now         func() time.Time // nil: time.Now
	Logger      *slog.Logger

	// PurgeNATS, when set, replaces the quarantine: it removes sqi's
	// JetStream state from an external broker. Set it or NATSDataDir, not
	// both.
	PurgeNATS func(ctx context.Context) error
}

Options says what Run restores, into which store.

type Result

type Result struct {
	BackupVersion int64    // 0 with InPlace
	Version       int64    // after migrate up
	Fenced        int      // attempts the fence handed back
	MovedAside    []string // where the previous database files went
	NATSDir       string   // the absolute directory looked at
	NATSMovedTo   string   // "" when there was none
	NATSPurged    bool     // PurgeNATS ran and succeeded
}

Result reports what Run did.

func Run

func Run(ctx context.Context, o Options) (Result, error)

Run restores o.Backup (or, with InPlace, the database already in place) and makes it safe to start a server on: lock, check, put in place, migrate, fence, then quarantine the NATS directory or, with an external broker, purge it. Each step must succeed before the next. The lock is held until Run returns.

Jump to

Keyboard shortcuts

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