backup

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 14 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 backup keeps copies of the server's SQLite database: before the schema changes in an upgrade, every day (by default), and whenever an admin asks. An admin can download one or restore it, which takes effect the next time the server starts. A PostgreSQL database is backed up with pg_dump instead.

Index

Constants

View Source
const (
	ReasonScheduled = "scheduled"
	ReasonManual    = "manual"
	ReasonUpgrade   = "upgrade"
	// The database as it was before a restore replaced it.
	ReasonRestore = "before-restore"
)

Why a backup was made.

Variables

View Source
var DefaultSettings = Settings{EveryHours: 24, Keep: 7}

DefaultSettings: a backup a day, a week of them.

Functions

func ApplyRestore

func ApplyRestore(ctx context.Context, dbPath, dir string, log *slog.Logger) (bool, error)

ApplyRestore, before the database is opened, puts a restore an admin asked for in place: the database as it is goes to the backups first. It reports whether it restored one.

func ValidName

func ValidName(name string) bool

ValidName says whether name is one of the backups' names (and nothing that leads anywhere else).

Types

type Backup

type Backup struct {
	Name   string `json:"name"`
	Size   int64  `json:"size"`
	Time   int64  `json:"time"` // milliseconds
	Reason string `json:"reason"`
}

Backup is one copy of the database.

type Manager

type Manager struct {
	Store *store.Store
	// Dir holds the backups; DBPath is the database file.
	Dir    string
	DBPath string
	Log    *slog.Logger
	// Failed hears about a backup that failed, for an admin alert.
	Failed func(ctx context.Context, err error)
	// contains filtered or unexported fields
}

Manager makes, lists and restores backups in Dir.

func (*Manager) BeforeMigrate

func (m *Manager) BeforeMigrate(s *store.Store, from, to int) error

BeforeMigrate backs up the database before an upgrade changes it; it's store.Options.BeforeMigrate. A backup that fails stops the upgrade, so the old database stays as it was.

func (*Manager) CancelRestore

func (m *Manager) CancelRestore() error

CancelRestore keeps the database as it is.

func (*Manager) Delete

func (m *Manager) Delete(name string) error

Delete removes a backup.

func (*Manager) LastError

func (m *Manager) LastError() string

LastError is why the latest backup failed, or "".

func (*Manager) List

func (m *Manager) List() ([]Backup, error)

List is the backups, newest first.

func (*Manager) Make

func (m *Manager) Make(ctx context.Context, reason string) (Backup, error)

Make backs up the database now.

func (*Manager) Path

func (m *Manager) Path(name string) (string, error)

Path is the file of the backup called name.

func (*Manager) PendingRestore

func (m *Manager) PendingRestore() string

PendingRestore is the backup that replaces the database at the next start, or "".

func (*Manager) Restore

func (m *Manager) Restore(ctx context.Context, name string) error

Restore puts the backup called name in place of the database the next time the server starts.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

Run makes a scheduled backup whenever one is due, until ctx ends.

func (*Manager) SaveSettings

func (m *Manager) SaveSettings(ctx context.Context, s Settings) (Settings, error)

SaveSettings stores them.

func (*Manager) Settings

func (m *Manager) Settings(ctx context.Context) Settings

Settings reads the admin's settings.

func (*Manager) Supported

func (m *Manager) Supported() bool

Supported says whether this server backs up its own database.

type Settings

type Settings struct {
	// EveryHours between scheduled backups; 0 turns them off.
	EveryHours int `json:"everyHours"`
	// Keep is how many of each kind are kept; older ones are deleted.
	Keep int `json:"keep"`
}

Settings is how often backups are made and how many are kept.

func (*Settings) Normalize

func (s *Settings) Normalize()

Normalize keeps the settings in range.

Jump to

Keyboard shortcuts

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