backup

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package backup provides database backup and restore utilities for goent.

It supports two database backends:

  • SQLite: full backups by copying the database file.
  • PostgreSQL: full backups using pg_dump schema + COPY data, and incremental backups using JSON Lines for rows changed since a base time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Dir is the directory where backup archives are stored.
	// If empty, the current working directory is used.
	Dir string

	// DSN is the database connection string used by external tools such as
	// pg_dump, psql, and for locating the SQLite database file.
	DSN string

	// DBPath is the explicit SQLite database file path. If empty, the engine
	// attempts to derive it from DSN.
	DBPath string

	// Schema is the PostgreSQL schema to back up. Defaults to "public".
	Schema string

	// LogTables are tables whose data should not be backed up.
	// Only structure is preserved for these tables.
	LogTables []string

	// ExcludedFromIncremental are tables that should be skipped in incremental
	// backups. Usually this includes log tables and the backup metadata table.
	ExcludedFromIncremental []string
}

Config customizes backup and restore behaviour.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine creates and restores database backups.

func New

func New(db *goent.DB, cfg Config) *Engine

New creates a backup engine for db with the provided configuration.

func (*Engine) Full

func (e *Engine) Full(ctx context.Context, name string) Result

Full creates a full backup archive and returns its metadata.

For SQLite this copies the database file. For PostgreSQL it dumps the schema and exports each non-log table with COPY.

func (*Engine) Incremental

func (e *Engine) Incremental(ctx context.Context, name string, since time.Time) Result

Incremental creates an incremental backup archive containing rows changed since the provided base time. The caller is responsible for choosing the correct base time, typically the started time of the last successful full backup.

func (*Engine) Restore

func (e *Engine) Restore(ctx context.Context, path string, incremental bool) error

Restore extracts and applies the backup archive at path.

If incremental is true, the engine expects a full backup archive to have been restored first; it will then apply the incremental changes on top.

type Result

type Result struct {
	Path        string
	Size        int64
	StartedAt   *time.Time
	CompletedAt *time.Time
	Err         error
}

Result contains metadata about a created backup archive.

Jump to

Keyboard shortcuts

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