backup

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PluginPresets = map[string]config.PluginConfig{
	"beads": {
		Name:    "beads",
		Command: "bd backup --force",
		Include: []string{".beads/backup/*"},
	},
	"beads-rust": {
		Name:    "beads-rust",
		Command: "beads backup --force",
		Include: []string{".beads/backup/*"},
	},
}

PluginPresets are built-in plugin configurations for common tools.

Functions

func ApplyRetention

func ApplyRetention(archivesDir string, retention config.RetentionConfig) error

ApplyRetention applies GFS (Grandfather-Father-Son) retention to archive files. Files matching "pre-restore-*.zip" are exempt from rotation.

func CompressCurrentToArchive

func CompressCurrentToArchive(currentDir, archivesDir string) (string, error)

CompressCurrentToArchive compresses the current/ backup directory into a timestamped zip in archives/. Returns the path to the created zip.

func CreateSafetyBackup

func CreateSafetyBackup(backupDir, repoName string) (string, error)

CreateSafetyBackup creates a pre-restore safety backup of the current/ directory. Returns the path to the created zip, or empty string if there was nothing to protect. Safety backups use the "pre-restore-" prefix which exempts them from GFS rotation.

func ExportConfigFiles

func ExportConfigFiles(thrumDir, backupDir string) error

ExportConfigFiles copies config, identity, and context files from thrumDir to the backup. Layout:

thrumDir/config.json           → backupDir/config/config.json
thrumDir/identities/*.json     → backupDir/config/identities/*.json
thrumDir/context/*.md          → backupDir/config/context/*.md

func FormatPluginResults

func FormatPluginResults(results []PluginResult) string

FormatPluginResults returns a human-readable summary of plugin results.

func ImportLocalTables

func ImportLocalTables(dbPath, localDir string) error

ImportLocalTables reads JSONL files from localDir and inserts rows into the SQLite database.

func PluginNames

func PluginNames(results []PluginResult) []string

PluginNames returns the names of plugins that successfully ran.

func WriteManifest

func WriteManifest(dir string, m *Manifest) error

WriteManifest writes a manifest.json to the given directory.

Types

type BackupOptions

type BackupOptions struct {
	BackupDir    string                  // resolved backup directory
	RepoName     string                  // used as subfolder name
	SyncDir      string                  // path to a-sync worktree
	ThrumDir     string                  // path to .thrum directory
	DBPath       string                  // path to messages.db
	ThrumVersion string                  // version string for manifest
	Retention    *config.RetentionConfig // optional: apply GFS rotation after backup
	Plugins      []config.PluginConfig   // optional: third-party backup plugins
	PostBackup   string                  // optional: command to run after backup completes
	RepoPath     string                  // project repo root (CWD for plugins/hooks)
}

BackupOptions configures a backup run.

type BackupResult

type BackupResult struct {
	CurrentDir     string
	Manifest       *Manifest
	SyncResult     SyncExportResult
	LocalResult    LocalExportResult
	PluginResults  []PluginResult
	PostHookResult *PostHookResult
}

BackupResult holds the outcome of a backup run.

func RunBackup

func RunBackup(opts BackupOptions) (*BackupResult, error)

RunBackup orchestrates a full backup: exports JSONL, SQLite local tables, config files, and writes a manifest.

type BackupScheduler added in v0.5.3

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

BackupScheduler runs periodic backups on a configurable interval. It follows the same pattern as daemon.PeriodicSyncScheduler.

func NewBackupScheduler added in v0.5.3

func NewBackupScheduler(interval time.Duration, buildOpts func() BackupOptions) *BackupScheduler

NewBackupScheduler creates a scheduler that calls RunBackup at the given interval. BuildOpts is called on each tick to construct fresh BackupOptions (allows dynamic config reload in the future).

func (*BackupScheduler) Start added in v0.5.3

func (s *BackupScheduler) Start(ctx context.Context)

Start begins the periodic backup loop. It blocks until ctx is canceled. The first backup runs after one full interval (not immediately on start).

type LocalExportResult

type LocalExportResult struct {
	Tables map[string]int // table name → row count
}

LocalExportResult holds counts from a local table export.

func ExportLocalTables

func ExportLocalTables(db *sql.DB, backupDir string) (LocalExportResult, error)

ExportLocalTables exports local-only SQLite tables as JSONL files. Writes to backupDir/local/<table_name>.jsonl.

type Manifest

type Manifest struct {
	Version      int            `json:"version"`
	Timestamp    time.Time      `json:"timestamp"`
	ThrumVersion string         `json:"thrum_version"`
	RepoName     string         `json:"repo_name"`
	Counts       ManifestCounts `json:"counts"`
}

Manifest records metadata about a backup snapshot.

func ReadManifest

func ReadManifest(dir string) (*Manifest, error)

ReadManifest reads a manifest.json from the given directory.

type ManifestCounts

type ManifestCounts struct {
	Events       int      `json:"events"`
	MessageFiles int      `json:"message_files"`
	LocalTables  int      `json:"local_tables"`
	ConfigFiles  int      `json:"config_files"`
	Plugins      []string `json:"plugins,omitempty"`
}

ManifestCounts holds item counts in the backup.

type PluginResult

type PluginResult struct {
	Name     string
	Command  string
	Files    int
	CmdError string // non-empty if command failed (non-fatal)
}

PluginResult holds the outcome of a single plugin backup.

func RunPlugins

func RunPlugins(plugins []config.PluginConfig, repoPath, backupDir string) ([]PluginResult, error)

RunPlugins executes backup plugins and collects their output files. Plugin failures are non-fatal: they are logged and the backup continues.

type PostHookResult

type PostHookResult struct {
	Command string
	Error   string // non-empty if command failed (non-fatal)
}

PostHookResult holds the outcome of a post-backup hook.

func RunPostBackup

func RunPostBackup(command, repoPath, backupDir, repoName, currentDir string) *PostHookResult

RunPostBackup executes the post-backup hook command. Failure is non-fatal: the error is captured in the result, not returned.

type RestoreOptions

type RestoreOptions struct {
	BackupDir   string                // resolved backup directory
	RepoName    string                // repo subfolder name
	ArchivePath string                // optional: specific zip to restore from (empty = use current/)
	SyncDir     string                // path to a-sync worktree to restore JSONL into
	ThrumDir    string                // path to .thrum directory
	DBPath      string                // path to messages.db
	Plugins     []config.PluginConfig // optional: plugins with restore commands
	RepoPath    string                // project repo root (CWD for plugin restore commands)
}

RestoreOptions configures a restore operation.

type RestoreResult

type RestoreResult struct {
	SafetyBackup string // path to pre-restore zip, if created
	Source       string // "current" or the archive path
}

RestoreResult holds the outcome of a restore.

func RunRestore

func RunRestore(opts RestoreOptions) (*RestoreResult, error)

RunRestore restores thrum data from a backup.

  1. Creates a safety backup if existing data is present
  2. Determines source (archive zip or current/)
  3. Copies JSONL files to sync worktree
  4. Imports local tables into SQLite
  5. Restores config files to .thrum/
  6. Removes messages.db so projector rebuilds on next daemon start

type SyncExportResult

type SyncExportResult struct {
	EventLines   int
	MessageFiles int
}

SyncExportResult holds counts from a sync data export.

func ExportSyncData

func ExportSyncData(syncDir, backupDir string) (SyncExportResult, error)

ExportSyncData copies JSONL event logs from the sync worktree to the backup directory. Layout: syncDir/events.jsonl → backupDir/events.jsonl

syncDir/messages/*.jsonl → backupDir/messages/*.jsonl

Jump to

Keyboard shortcuts

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