backup

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 25 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 creates and restores bubbles backup archives (.bbk).

An archive is a tar.gz stream, age-encrypted with a passphrase by default:

db/bubbles.db      consistent VACUUM INTO snapshot
files/**           uploaded blobs and thumbnails
tls/**             local CA, leaf certificate and keys
vapid.json         Web Push signing key (when present)
settings.json      export of the settings table (informational)
manifest.json      last entry: format, version, sha256 of every other entry

The manifest comes last so entries can be streamed while their hashes are computed; restore verifies every hash before anything touches the target.

Index

Constants

View Source
const (
	FormatVersion = 1
	ManifestName  = "manifest.json"
	SettingsName  = "settings.json"
	DBEntry       = "db/bubbles.db"
	VAPIDEntry    = "vapid.json"
)

Archive layout constants.

View Source
const (
	MaxEntrySize int64 = 16 << 30
	MaxTotalSize int64 = 1 << 40
	MaxEntries         = 1_000_000
)

Limits applied while extracting an untrusted archive.

Variables

View Source
var (
	ErrNoDatabase         = errors.New("no database found in the data directory")
	ErrPassphraseRequired = errors.New("a passphrase is required")
	ErrWrongPassphrase    = errors.New("wrong passphrase or corrupted backup")
	ErrNotBackup          = errors.New("not a bubbles backup archive")
	ErrChecksum           = errors.New("backup integrity check failed")
	ErrUnsafePath         = errors.New("backup contains an unsafe entry")
	ErrNonEmpty           = errors.New("data directory is not empty (use --force to replace its contents)")
)

Errors returned by Create and Restore. Test with errors.Is.

Functions

func Create

func Create(ctx context.Context, dataDir string, w io.Writer, opts CreateOptions) error

Create writes a backup of dataDir to w. It does not take the data-directory lock: the database is copied with VACUUM INTO over a separate connection, so a running server keeps working. The temporary snapshot is always removed.

func Restore

func Restore(ctx context.Context, r io.Reader, dataDir string, opts RestoreOptions) (err error)

Restore unpacks the archive from r into dataDir. It refuses while a server holds the data-directory lock (error wrapping config.ErrLocked) and when the directory already has content unless opts.Force is set. The archive is extracted into a staging directory beside dataDir, every entry is verified against the manifest hashes, and only then are the pieces renamed into place. On any failure dataDir is left as it was.

Types

type CreateOptions

type CreateOptions struct {
	// Passphrase encrypts the archive (age scrypt). Required unless NoEncrypt.
	Passphrase string
	// NoEncrypt writes a plain tar.gz. The archive then contains the CA
	// private key in the clear; callers must warn the user.
	NoEncrypt bool
	// WorkFactor overrides the scrypt work factor (log2 N); 0 uses age's default.
	WorkFactor int
	// Now and Version are injectable for tests.
	Now     func() time.Time
	Version string
}

CreateOptions configures Create.

type Entry

type Entry struct {
	Path   string `json:"path"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256"`
}

Entry describes one archived file.

type Manifest

type Manifest struct {
	Format         int     `json:"format"`
	BubblesVersion string  `json:"bubbles_version"`
	CreatedAt      string  `json:"created_at"`
	InstanceID     string  `json:"instance_id"`
	SchemaVersion  int     `json:"schema_version"`
	Entries        []Entry `json:"entries"`
}

Manifest is the last entry of every archive.

type RestoreOptions

type RestoreOptions struct {
	// Passphrase decrypts an encrypted archive; plain archives ignore it.
	Passphrase string
	// Force replaces an existing, non-empty data directory's contents.
	Force bool
}

RestoreOptions configures Restore.

Jump to

Keyboard shortcuts

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