Help us shape the future of Go! Take the 2026 Go Developer Survey

backup

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package backup provides database backup and restore utilities. Currently supports PostgreSQL (via pg_dump/psql) and MySQL (via mysqldump/mysql). Backups are compressed with gzip and can be stored on any storage.Disk.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Upload

func Upload(ctx context.Context, m *Manager, disk storage.Disk, remotePath string) error

Upload compresses and streams a dump directly to a remote disk. This is more memory-efficient than writing to disk first.

Types

type BackupFile

type BackupFile struct {
	Name string
	Path string
	Size int64
	At   time.Time
}

BackupFile describes a backup on disk.

type Config

type Config struct {
	Driver   Driver
	Host     string
	Port     int
	User     string
	Password string
	DBName   string
	// BackupDir is where backup files are stored locally.
	BackupDir string
	Logger    *slog.Logger
}

Config holds database connection info for the backup tool.

type Driver

type Driver string

Driver represents a database dialect.

const (
	DriverPostgres Driver = "postgres"
	DriverMySQL    Driver = "mysql"
)

type Manager

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

Manager handles backup and restore operations.

func New

func New(cfg Config) *Manager

New creates a backup Manager.

func (*Manager) Backup

func (m *Manager) Backup(ctx context.Context) (string, error)

Backup creates a compressed backup and returns the file path.

func (*Manager) List

func (m *Manager) List() ([]BackupFile, error)

List returns all backup files in the backup directory, newest first.

func (*Manager) Restore

func (m *Manager) Restore(ctx context.Context, path string) error

Restore restores a database from a .sql.gz file.

Jump to

Keyboard shortcuts

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