backup

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package backup produces and restores a single-file archive of a moth data directory: an online-consistent snapshot of the SQLite database plus the uploads and key material.

The database is never copied byte-for-byte — a live WAL-mode file is not safe to read while the server is writing. Instead VACUUM INTO writes a fresh, transactionally-consistent copy that captures every committed write up to the moment it runs, so a backup can be taken under load. The result is a gzip-compressed tar; Restore reverses it with traversal and overwrite guards.

Index

Constants

View Source
const DBArchiveName = "moth.db"

DBArchiveName is the path of the vacuumed database inside the archive; on Restore it lands at <dataDir>/moth.db.

Variables

This section is empty.

Functions

func Backup

func Backup(ctx context.Context, dbPath, dataDir string, out io.Writer) error

Backup writes a gzip-compressed tar snapshot to out. dbPath is the live SQLite database; dataDir holds the uploads/ and keys/ subtrees. Missing subtrees are skipped (a fresh instance may have no uploads yet). The snapshot is taken with VACUUM INTO, so it is safe to call while the server is serving traffic.

func Restore

func Restore(archive io.Reader, dataDir string, force bool) error

Restore extracts an archive produced by Backup into dataDir. Unless force is set it refuses to write into a non-empty dataDir, so an accidental restore cannot silently clobber a live instance. Every archive member is validated against path traversal before anything is written.

Types

This section is empty.

Jump to

Keyboard shortcuts

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