backup

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package backup creates and restores tar.gz snapshots of the data directory (SQLite DB, certs, generated config, ACME account). The master state needed to reproduce a working panel lives entirely under the data dir.

Index

Constants

View Source
const LocalBackupDir = "backups"

LocalBackupDir is the subdirectory of the data dir holding scheduled local archives. WriteWithManifest skips it, so archives never nest inside each other.

Variables

This section is empty.

Functions

func ApplyPending

func ApplyPending(dataDir string) (applied bool, err error)

ApplyPending applies a staged restore (if any) over dataDir, then clears the staging area. Call it on boot before opening the database. No-op when nothing is staged. Re-downloadable assets not present in the backup (bin/, geo/) are left in place.

func Create

func Create(dataDir, out string) error

Create writes a gzip-compressed tar of dataDir to the named file.

func ListLocal added in v0.13.0

func ListLocal(dataDir string) ([]string, error)

ListLocal returns the local archive file names, newest first.

func Restore

func Restore(file, dataDir string) error

Restore extracts a backup tarball into dataDir (which must exist).

func Rotate added in v0.13.0

func Rotate(dataDir string, keep int) (removed int, err error)

Rotate deletes the oldest local archives, keeping the newest keep. keep <= 0 disables rotation (retain everything) rather than deleting the lot — a zero value from an unset config must never be read as "erase every backup I have".

func StageRestore

func StageRestore(file, dataDir string) error

StageRestore unpacks a backup into a staging area inside dataDir and marks it ready. The restore is applied by ApplyPending on the next boot, BEFORE the database is opened — so a live SQLite WAL can't checkpoint stale data back over the restored DB (which would silently revert the restore). On failure the live data is left untouched.

func WriteLocal added in v0.13.0

func WriteLocal(dataDir string, m Manifest, checkpoint func() error, now time.Time) (string, error)

WriteLocal builds a backup archive into <dataDir>/backups and returns its path. checkpoint (may be nil) flushes the DB's WAL first so the archived DB is complete.

The archive is written to a temp name in the same directory and renamed into place, so a crash mid-write can't leave a truncated file that looks like a valid backup — and so Rotate never sees a half-written archive as a rotation candidate.

func WriteWithManifest

func WriteWithManifest(dataDir string, m Manifest, w io.Writer) error

WriteWithManifest streams a gzip-compressed tar of dataDir to w, prepending manifest.json as the first entry so inspectors can peek at it cheaply.

Types

type Manifest

type Manifest struct {
	Domain     string `json:"domain"`
	SecretPath string `json:"secret_path"`
	UserCount  int    `json:"user_count"`
	CreatedAt  string `json:"created_at"`
}

Manifest is written as manifest.json (the first tar entry) in every backup. It lets the operator preview what a backup contains before restoring.

func ReadManifest

func ReadManifest(r io.Reader) (Manifest, error)

ReadManifest reads the manifest.json entry from a backup tar.gz stream. It stops reading as soon as the manifest is found, so only a small prefix of a large archive needs to be decompressed.

Jump to

Keyboard shortcuts

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