backup

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: GPL-3.0 Imports: 8 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 copies the state hlab keeps on a machine back to where hlab runs, and puts it back again.

What it protects is small and irreplaceable: a DNS zone, a DHCP lease database, service credentials, printer configuration. What it deliberately does not protect is bulk data mounted from elsewhere on the machine — a media library is large, is not hlab's, and would turn a cheap safety net into something nobody runs.

Index

Constants

View Source
const (
	MarkerBegin    = "##HLAB#BACKUP#"
	MarkerEnd      = "##HLAB#ENDBACKUP#"
	MarkerNothing  = "hlab:nothing-to-back-up"
	MarkerRestored = "hlab:restored"
)

Markers delimiting the archive in the script's output.

View Source
const RemoteDir = "/opt/hlab/stacks"

RemoteDir is the directory backed up on each machine.

View Source
const StageCommand = "sh -c 'cat > /tmp/hlab-restore.b64'"

StageCommand is the command that receives a base64 archive on stdin.

The data travels as the command's input rather than inside the script, because a script carrying twenty megabytes of payload is awkward to quote and impossible to read when something goes wrong.

Variables

View Source
var ErrNothing = errors.New("nothing to back up")

ErrNothing means the machine has no hlab-managed state. That is an ordinary answer, not a failure: most machines in a fleet run no stacks, and treating them as errors would make a healthy run exit non-zero and be useless to anything scheduled.

View Source
var Excluded = []string{
	"*.log", "*.log.*", "logs",
	"blocklists", "stats", "cache.bin", ".cache", "deps", "tts",
	"*.db", "*.db-wal", "*.db-shm",
	"*.sqlite", "*.sqlite-wal", "*.sqlite-shm",
}

Excluded holds the patterns left out of an archive.

The point of this backup is rebuilding a machine, not preserving its history. Everything here is either regenerated on first run, or is live state that should not be restored at all:

  • Logs and caches come back on their own and dominate the archive — unfiltered, a fleet of a few megabytes of configuration was carried as fourteen megabytes of DNS blocklists and printer agent logs, plus several hundred downloaded UI icons.
  • A database copied while its service is running is the dangerous one. The file plus its write-ahead log is an inconsistent snapshot, and restoring it can produce a corrupt database rather than an old one. Home Assistant's recorder holds history, which is data rather than configuration, and is excluded for both reasons.

Functions

func BuildArchiveScript

func BuildArchiveScript() string

BuildArchiveScript renders the script that produces a backup.

func BuildRestoreScript

func BuildRestoreScript(sha256sum, stamp string) (string, error)

BuildRestoreScript renders the script that puts a backup back.

Types

type Archive

type Archive struct {
	Host   string
	Data   []byte
	SHA256 string
	Files  int
}

Archive is one machine's backup, already verified.

func ParseArchive

func ParseArchive(host, raw string) (Archive, error)

ParseArchive extracts and verifies the archive from a machine's output.

Both the checksum and the length are checked, against the values the machine computed on the file it actually wrote. That is the whole point: a truncated transfer produces a tar that looks plausible and fails only when somebody is trying to restore from it, which is the worst possible moment to find out.

Jump to

Keyboard shortcuts

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