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 ¶
var ErrNotSQIBackup = errors.New("restore: not an sqi backup")
ErrNotSQIBackup means the file is not a database or archive sqi wrote.
Functions ¶
func Fence ¶
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 ¶
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.