backup

package
v1.0.1-beta-6 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT, Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const BackupFilenamePrefix = "tbl_backup"

BackupFilenamePrefix is the prefix used in every backup file.

Variables

This section is empty.

Functions

func Compress

func Compress(filepath string) (string, error)

Compress compresses a file using zstd.

func Decompress

func Decompress(filepath string) (string, error)

Decompress decompresses a zstd file.

func Prune

func Prune(dir string, keep int) error

Prune prunes the directory keeping the n most recent backup files.

Types

type BackupResult

type BackupResult struct {
	Timestamp time.Time
	Path      string

	// Stats
	ElapsedTime            time.Duration
	VacuumElapsedTime      time.Duration
	CompressionElapsedTime time.Duration
	Size                   int64
	SizeAfterVacuum        int64
	SizeAfterCompression   int64
}

BackupResult represents the result of a backup process.

type Backuper

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

Backuper is the process that executes the backup process.

func NewBackuper

func NewBackuper(sourcePath string, backupDir string, opts ...Option) (*Backuper, error)

NewBackuper creates a new backuper responsible for making backups of a SQLite database.

func (*Backuper) Backup

func (b *Backuper) Backup(ctx context.Context) (_ BackupResult, err error)

Backup creates a backup to a file in disk. Multiple serial calls to Backup can be perfomed. This can be used to perform retries in case of errors.

func (*Backuper) Close

func (b *Backuper) Close() error

Close closes the backuper and backups cannot be taken anymore.

type BackuperOptions

type BackuperOptions struct {
	SourcePath, BackupDir string
	Opts                  []Option
}

BackuperOptions options needed to instantiate a backuper.

type Config

type Config struct {
	Compression bool
	Pruning     bool
	Vacuum      bool
	KeepFiles   int
}

Config contains configuration parameters for backuper.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration.

type DB

type DB interface {
	Close() error
	Ping() error
	SetMaxOpenConns(n int)
	Conn(context.Context) (*sql.Conn, error)
	Exec(query string, args ...interface{}) (sql.Result, error)

	// new
	Path() string
}

DB is a subset of *sql.DB operations used in Backuper. This interfaces aids with testing.

type Database

type Database struct {
	*sql.DB
	// contains filtered or unexported fields
}

Database is the implementation of DB used in Backuper. It inherits *sql.DB.

func (*Database) Path

func (db *Database) Path() string

Path returns the path of the database.

type Option

type Option func(*Config) error

Option modifies a configuration attribute.

func WithCompression

func WithCompression(v bool) Option

WithCompression enables compression.

func WithPruning

func WithPruning(v bool, keep int) Option

WithPruning enables pruning of old backup files.

func WithVacuum

func WithVacuum(v bool) Option

WithVacuum enables VACUUM operation.

type Scheduler

type Scheduler struct {
	NotificationCh chan error
	// contains filtered or unexported fields
}

Scheduler executes backups at a regular interval.

func NewScheduler

func NewScheduler(frequency int, opts BackuperOptions, notify bool) (*Scheduler, error)

NewScheduler creates a new backup scheduler.

func (*Scheduler) Run

func (s *Scheduler) Run()

Run starts the scheduler and listens for a shutdown call.

func (*Scheduler) Shutdown

func (s *Scheduler) Shutdown()

Shutdown gracefully shutdowns the scheduler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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