Documentation
¶
Overview ¶
Package backup provides database backup and restore functionality. It supports incremental backups using BadgerDB's native backup mechanism with optional zstd compression.
Index ¶
- Constants
- Variables
- type Config
- type Metadata
- type Service
- func (s *Service) Backup(w io.Writer, since uint64, compress bool) (uint64, error)
- func (s *Service) BackupChunked(since uint64, compress bool) (<-chan []byte, <-chan error, <-chan uint64)
- func (s *Service) BackupToFile(path string, since uint64, compress bool) (uint64, error)
- func (s *Service) GetLastVersion() uint64
- func (s *Service) GetMetadata() *Metadata
- func (s *Service) Restore(r io.Reader, compressed bool) error
- func (s *Service) RestoreChunked(compressed bool) (chan<- []byte, <-chan error)
- func (s *Service) RestoreFromFile(path string, compressed bool) error
Constants ¶
const ( // DefaultChunkSize is the default size of backup chunks (1MB). DefaultChunkSize = 1 << 20 // MetadataFileName is the name of the backup metadata file. MetadataFileName = "backup_metadata.json" )
Variables ¶
var ( // ErrDatabaseClosed is returned when the database is closed. ErrDatabaseClosed = errors.New("database is closed") // ErrBackupInProgress is returned when a backup is already in progress. ErrBackupInProgress = errors.New("backup already in progress") // ErrRestoreInProgress is returned when a restore is already in progress. ErrRestoreInProgress = errors.New("restore already in progress") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// DB is the database to backup/restore.
DB database.Database
// MetadataDir is the directory to store backup metadata.
MetadataDir string
// ChunkSize is the size of backup chunks in bytes.
ChunkSize int
// Log is the logger.
Log log.Logger
}
Config configures the backup service.
type Metadata ¶
type Metadata struct {
LastVersion uint64 `json:"lastVersion"`
LastBackupTime time.Time `json:"lastBackupTime"`
LastBackupSize uint64 `json:"lastBackupSize"`
Incremental bool `json:"incremental"`
}
Metadata stores information about the last backup.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides backup and restore operations.
func (*Service) Backup ¶
Backup performs a database backup, writing to the provided writer. since: 0 for full backup, or the version from the last backup for incremental. compress: whether to compress the output with zstd. Returns the new version number for future incremental backups.
func (*Service) BackupChunked ¶
func (s *Service) BackupChunked(since uint64, compress bool) (<-chan []byte, <-chan error, <-chan uint64)
BackupChunked performs a backup and returns data in chunks. This is useful for streaming backups over gRPC.
func (*Service) BackupToFile ¶
BackupToFile performs a backup to a file path.
func (*Service) GetLastVersion ¶
GetLastVersion returns the version of the last backup. Returns 0 if no backup has been performed.
func (*Service) GetMetadata ¶
GetMetadata returns the current backup metadata.
func (*Service) Restore ¶
Restore restores the database from the provided reader. The reader should contain backup data (optionally zstd compressed).
func (*Service) RestoreChunked ¶
RestoreChunked restores from chunks. Send chunks to the returned channel, close when done.