backup

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package backup builds and verifies graphdb store backup archives.

An archive is a gzip+tar of a store's dataDir: the snapshot file plus the wal/, auth/, lsa/, and edgestore/ trees, with a manifest trailer recording per-file size + SHA-256 for integrity. The package has no dependency on the HTTP server (pkg/api) or storage, so offline tooling (the graphdb-admin CLI) can build, verify, and restore archives without opening a graph.

Index

Constants

View Source
const ManifestName = "manifest.json"

ManifestName is the archive member holding the manifest.

View Source
const ManifestVersion = 1

ManifestVersion is the schema version of the manifest envelope. Bump when the manifest shape changes incompatibly; verify/restore tooling refuses versions it does not understand.

Variables

This section is empty.

Functions

func Extract

func Extract(r io.Reader, destDir string) error

Extract unpacks a backup archive into destDir, reconstructing the store's dataDir layout. The manifest.json metadata entry is skipped — only the store's own files are written. destDir is created if absent.

Each entry's destination is constrained to destDir: an entry whose path escapes the directory (a "zip-slip" traversal) aborts the extraction with an error. Callers should Verify the archive first; Extract performs no integrity checking of its own.

func WriteArchive

func WriteArchive(w io.Writer, dataDir, version string) error

WriteArchive streams a gzip+tar archive of the store's dataDir to w: each backup file with its dataDir-relative path, then a manifest.json trailer.

Types

type File

type File struct {
	Path      string `json:"path"`       // path relative to dataDir, slash-separated
	SizeBytes int64  `json:"size_bytes"` // bytes written into the archive
	Sha256    string `json:"sha256"`     // hex SHA-256 of exactly those bytes
}

File records one archived member with the integrity data needed to detect a corrupt or truncated archive before it is restored over live data.

type Manifest

type Manifest struct {
	ManifestVersion int    `json:"manifest_version"`
	GraphdbVersion  string `json:"graphdb_version"`
	CreatedAtUTC    string `json:"created_at_utc"`
	SnapshotMode    string `json:"snapshot_mode"` // "json" | "mmap" | "none"
	Files           []File `json:"files"`
}

Manifest is the provenance + integrity record. It is written as the archive's LAST entry (a trailer) so each file's recorded hash describes exactly the bytes streamed into the tar — immune to a WAL segment being appended between enumeration and streaming on a live backup.

func Verify

func Verify(r io.Reader) (*Manifest, error)

Verify reads a backup archive stream and checks its integrity against the manifest trailer: every manifest file must be present with a matching size and SHA-256, and every archived file (other than the manifest) must be listed. It returns the parsed manifest on success, or an error naming the offending path(s). It does not write anything — safe to run against an archive before restoring it over live data.

Jump to

Keyboard shortcuts

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