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 ¶
const ( FormatVersion = 1 ManifestName = "manifest.json" SettingsName = "settings.json" DBEntry = "db/bubbles.db" VAPIDEntry = "vapid.json" )
Archive layout constants.
const ( MaxEntrySize int64 = 16 << 30 MaxTotalSize int64 = 1 << 40 MaxEntries = 1_000_000 )
Limits applied while extracting an untrusted archive.
Variables ¶
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 ¶
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 ¶
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.