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
- Variables
- func ApplyRestore(ctx context.Context, dbPath, dir string, log *slog.Logger) (bool, error)
- func ValidName(name string) bool
- type Backup
- type Manager
- func (m *Manager) BeforeMigrate(s *store.Store, from, to int) error
- func (m *Manager) CancelRestore() error
- func (m *Manager) Delete(name string) error
- func (m *Manager) LastError() string
- func (m *Manager) List() ([]Backup, error)
- func (m *Manager) Make(ctx context.Context, reason string) (Backup, error)
- func (m *Manager) Path(name string) (string, error)
- func (m *Manager) PendingRestore() string
- func (m *Manager) Restore(ctx context.Context, name string) error
- func (m *Manager) Run(ctx context.Context)
- func (m *Manager) SaveSettings(ctx context.Context, s Settings) (Settings, error)
- func (m *Manager) Settings(ctx context.Context) Settings
- func (m *Manager) Supported() bool
- type Settings
Constants ¶
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 ¶
var DefaultSettings = Settings{EveryHours: 24, Keep: 7}
DefaultSettings: a backup a day, a week of them.
Functions ¶
func ApplyRestore ¶
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.
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 ¶
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 ¶
CancelRestore keeps the database as it is.
func (*Manager) PendingRestore ¶
PendingRestore is the backup that replaces the database at the next start, or "".
func (*Manager) Restore ¶
Restore puts the backup called name in place of the database the next time the server starts.
func (*Manager) SaveSettings ¶
SaveSettings stores them.