Documentation
¶
Overview ¶
Package backup creates and restores consistent snapshots of the nebula-mgmt control-plane database. A backup is a gzipped tar holding a manifest and a SQLite snapshot taken with VACUUM INTO (correct under WAL), optionally AES-256-GCM encrypted under an operator passphrase so archives can be shipped to untrusted storage (#229).
The master key is deliberately NOT part of the archive: the encrypted CA private keys in the snapshot are useless without it, so restore requires the operator to supply the same NEBULA_MGMT_MASTER_KEY out of band. The caller (internal/cli) verifies that key can actually decrypt the restored CAs before declaring success.
Index ¶
Constants ¶
const (
// FormatVersion is the archive layout version recorded in the manifest.
FormatVersion = 1
)
Variables ¶
var ( ErrPassphraseRequired = errors.New("archive is encrypted: a passphrase is required") ErrDecryptFailed = errors.New("decryption failed: wrong passphrase or corrupt archive") ErrCorruptArchive = errors.New("backup archive is corrupt or truncated") ErrUnsupportedFormat = errors.New("unsupported backup format version") ErrMissingDB = errors.New("backup archive does not contain a database snapshot") )
Sentinel errors callers can match on.
Functions ¶
func Create ¶
func Create(ctx context.Context, db *sql.DB, w io.Writer, meta Meta, passphrase, tmpDir string) error
Create writes a consistent, gzipped tar snapshot of db to w. When passphrase is non-empty the whole archive is AES-256-GCM encrypted (scrypt KDF) and prefixed with the magic header. tmpDir is where the transient VACUUM INTO snapshot is written — pass a directory on the same filesystem as the DB; it is removed before Create returns.
Types ¶
type Manifest ¶
type Manifest struct {
FormatVersion int `json:"format_version"`
AppVersion string `json:"app_version"`
SchemaVersion string `json:"schema_version"`
CreatedAt time.Time `json:"created_at"`
DBFilename string `json:"db_filename"`
}
Manifest is the metadata stored alongside the database snapshot.
func Restore ¶
Restore reads an archive from r, decrypting it when it carries the encrypted magic (which requires passphrase), validates the manifest, and writes the embedded database to destDBPath. destDBPath must not already exist — Restore never overwrites a database. It returns the parsed manifest.