knoxite

package module
v0.0.0-...-f81bbf2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: AGPL-3.0 Imports: 33 Imported by: 0

README ΒΆ

knoxite

Build Status Coverage Status Go ReportCard GoDoc

knoxite is a secure data storage & backup system.

Join the discussion on IRC in #knoxite (on irc.libera.chat) or our Gitter chat room!

πŸ”’ It's secure

knoxite uses AES-encryption to safely store your data.

πŸ’ͺ It's flexible

You can always extend your storage size or move your stored data to another machine.

πŸš€ It's efficient

knoxite cleverly de-duplicates your data before storing it and supports multiple compression algorithms.

πŸ”— It's connected

You can use multiple storage backends, even parallely: local disks, Dropbox, Amazon S3 & others.

❀ It's OpenSource

knoxite is free software. Contribute and spread the word!

Installation

Make sure you have a working Go environment. Follow the Go install instructions.

To install knoxite, simply run:

git clone https://github.com/knoxite/knoxite.git
cd knoxite
go build ./cmd/knoxite/

Or use your favourite package manager:

# Arch Linux (btw)
yay -S knoxite-git

Run knoxite --help to see a full list of options.

Getting started

Initialize a repository

First of all we need to initialize an empty directory (in this case /tmp/knoxite) as a repository:

$ knoxite -r /tmp/knoxite repo init
Enter password:
Created new repository at /tmp/knoxite

knoxite encrypts all the data in the repository with the supplied password. Be warned: if you lose this password, you won't be able to access any of your data.

Initialize a volume

Each repository can contain several volumes, which store our data organized in snapshots. So let's create one:

$ knoxite -r /tmp/knoxite volume init "Backups" -d "My system backups"
Volume 66e03034 (Name: Backups, Description: My system backups) created
List all volumes

Now you can get a list of all volumes stored in this repository:

$ knoxite -r /tmp/knoxite volume list
ID        Name                              Description
----------------------------------------------------------------------------------------------
66e03034  Backups                           My system backups
Storing data in a volume

Run the following command to create a new snapshot and store your home directory in the newly created volume:

$ knoxite -r /tmp/knoxite store [volume ID] $HOME -d "Backup of all my data"
document.txt          5.69 MiB / 5.69 MiB [#########################################] 100.00%
other.txt             4.17 MiB / 4.17 MiB [#########################################] 100.00%
...
Snapshot cebc1213 created: 9 files, 8 dirs, 0 symlinks, 0 errors, 1.23 GiB Original Size, 1.23 GiB Storage Size

When errors occur while storing individual data-chunks knoxite still tries to complete the store operation for the remaining chunks. You can toggle this behaviour to immediately exit on the first erroroneus data-chunk by setting the --pedantic command line flag.

List all snapshots

Now you can get an overview of all snapshots stored in this volume:

$ knoxite -r /tmp/knoxite snapshot list [volume ID]
ID        Date                 Original Size  Storage Size  Description
----------------------------------------------------------------------------------------------
cebc1213  2016-07-29 02:27:15       1.23 GiB      1.23 GiB  Backup of all my data
----------------------------------------------------------------------------------------------
                                    1.23 GiB      1.23 GiB
Show the content of a snapshot

Running the following command lists the entire content of a snapshot:

$ knoxite -r /tmp/knoxite ls [snapshot ID]
Perms       User   Group          Size  ModTime              Name
----------------------------------------------------------------------------------------------
-rw-r--r--  user   group      5.69 MiB  2016-07-29 02:06:04  document.txt
-rw-r--r--  user   group      4.17 MiB  2016-07-29 02:05:22  other.txt
...
Show the content of a snapshotted file

With the following command you can also print out the files content to stdout:

$ knoxite -r /tmp/knoxite cat [snapshot ID] document.txt
This is the sample text stored in document.txt
Restoring a snapshot

To restore the latest snapshot to /tmp/myhome, run:

$ knoxite -r /tmp/knoxite restore [snapshot ID] /tmp/myhome
document.txt          5.69 MiB / 5.69 MiB [#########################################] 100.00%
other.txt             4.17 MiB / 4.17 MiB [#########################################] 100.00%
...
Restore done: 9 files, 8 dirs, 0 symlinks, 0 errors, 1.23 GiB Original Size, 1.23 GiB Storage Size
Cloning a snapshot

Adds target file or directory to an existing snapshot:

$ knoxite -r /tmp/knoxite clone [snapshot ID] $HOME
document.txt          5.89 MiB / 5.89 MiB [#########################################] 100.00%
other.txt             5.10 MiB / 5.10 MiB [#########################################] 100.00%
...
Snapshot aefc4591 created: 9 files, 8 dirs, 0 symlinks, 0 errors, 1.34 GiB Original Size, 1.34 GiB Storage Size
Mounting a snapshot

You can even mount a snapshot (currently read-only, read-write is work-in-progress):

$ knoxite -r /tmp/knoxite mount [snapshot ID] /mnt
Backup. No more excuses.

Configuration System

Knoxite comes bundled with a configuration system. You can declare shorthands for your repositories and provide default values for settings like encryption, compression or excludes. For more information refer to the documentation on our website or take a look into the knoxite config command.

Optional environment variables

Optionally you can set the KNOXITE_REPOSITORY and KNOXITE_PASSWORD environment variables to provide default settings for when no options have been passed to knoxite.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	File      = iota // A File
	Directory        // A Directory
	SymLink          // A SymLink
)

Types of archives.

View Source
const (
	CompressionNone = iota
	CompressionGZip
	CompressionLZMA
	CompressionFlate
	CompressionZlib
	CompressionZstd
)

Available compression algos.

View Source
const (
	EncryptionNone = iota
	EncryptionAES
)

Available encryption algos.

View Source
const (
	HashSha256 = iota
	HashHighway256
)

Available hash algos.

View Source
const (
	LogLevelFatal = iota
	LogLevelWarning
	LogLevelPrint
	LogLevelInfo
	LogLevelDebug
)
View Source
const (
	// RepoFilename is the default filename for the repository data.
	RepoFilename = "repository.knoxite"
	// ChunkIndexFilename is the default filename for the chunk-index.
	ChunkIndexFilename = "index"
)
View Source
const (
	RepositoryVersion = 4
)

Const declarations.

Variables ΒΆ

View Source
var (
	ErrRepositoryExists        = errors.New("repository seems to already exist")
	ErrInvalidRepositoryURL    = errors.New("invalid repository url specified")
	ErrAvailableSpaceUnknown   = errors.New("available space is unknown or undefined")
	ErrAvailableSpaceUnlimited = errors.New("available space is unlimited")
	ErrInvalidUsername         = errors.New("username wrong or missing")
)

Error declarations.

View Source
var (
	ErrLoadChunkFailed       = errors.New("unable to load chunk from any storage backend")
	ErrLoadSnapshotFailed    = errors.New("unable to load snapshot from any storage backend")
	ErrLoadChunkIndexFailed  = errors.New("unable to load chunk-index from any storage backend")
	ErrLoadRepositoryFailed  = errors.New("unable to load repository from any storage backend")
	ErrDeleteChunkFailed     = errors.New("unable to delete chunk from any storage backend")
	ErrStoreChunkFailed      = errors.New("storing chunk failed")
	ErrStoreSnapshotFailed   = errors.New("storing snapshot failed")
	ErrStoreChunkIndexFailed = errors.New("storing chunk-index failed")
	ErrStoreRepositoryFailed = errors.New("storing repository failed")
)

Error declarations.

View Source
var (
	ErrRepositoryIncompatible  = errors.New("the repository is not compatible with this version of Knoxite")
	ErrOpenRepositoryFailed    = errors.New("wrong password or corrupted repository")
	ErrVolumeNotFound          = errors.New("volume not found")
	ErrSnapshotNotFound        = errors.New("snapshot not found")
	ErrGenerateRandomKeyFailed = errors.New("failed to generate a random encryption key for new repository")
)

Error declarations.

View Source
var (
	ErrInvalidPassword = errors.New("empty password not permitted")
)

Error declarations.

Functions ΒΆ

func DecodeArchive ΒΆ

func DecodeArchive(progress chan<- Progress, repository Repository, arc Archive, path string) error

DecodeArchive restores a single archive to path.

func DecodeSnapshot ΒΆ

func DecodeSnapshot(repository Repository, snapshot *Snapshot, dst string, excludes []string, pedantic bool) (<-chan Progress, error)

DecodeSnapshot restores an entire snapshot to dst.

func Hash ΒΆ

func Hash(b []byte, hashtype uint8) string

Hash data.

func ReadArchive ΒΆ

func ReadArchive(repository Repository, arc Archive, offset int, size int) (*[]byte, error)

ReadArchive reads from an archive.

func RegisterStorageBackend ΒΆ

func RegisterStorageBackend(factory BackendFactory)

RegisterStorageBackend needs to be called by storage backends to register themselves.

func SetLogger ΒΆ

func SetLogger(l Logger)

func SizeToString ΒΆ

func SizeToString(size uint64) (str string)

SizeToString prettifies sizes.

func SubDirForChunk ΒΆ

func SubDirForChunk(id string) string

SubDirForChunk files a chunk into a subdir, based on the chunks name.

func VerifyArchive ΒΆ

func VerifyArchive(repository Repository, arc Archive) error

func VerifyRepo ΒΆ

func VerifyRepo(repository Repository, percentage int) (<-chan Progress, error)

func VerifySnapshot ΒΆ

func VerifySnapshot(repository Repository, snapshotId string, percentage int) (<-chan Progress, error)

func VerifyVolume ΒΆ

func VerifyVolume(repository Repository, volumeId string, percentage int) (<-chan Progress, error)

Types ΒΆ

type Archive ΒΆ

type Archive struct {
	Path        string      `json:"path"`               // Where in filesystem does this belong to
	PointsTo    string      `json:"pointsto,omitempty"` // If this is a SymLink, where does it point to
	Mode        os.FileMode `json:"mode"`               // file mode bits
	ModTime     int64       `json:"modtime"`            // modification time
	Size        uint64      `json:"size"`               // size
	StorageSize uint64      `json:"storagesize"`        // size in storage
	UID         uint32      `json:"uid"`                // owner
	GID         uint32      `json:"gid"`                // group
	Chunks      []Chunk     `json:"chunks,omitempty"`   // data chunks
	Encrypted   uint16      `json:"encrypted"`          // encryption type
	Compressed  uint16      `json:"compressed"`         // compression type
	Type        uint8       `json:"type"`               // Is this a File, Directory or SymLink
}

Archive contains all metadata belonging to a file/directory.

func (*Archive) ChunkForOffset ΒΆ

func (arc *Archive) ChunkForOffset(offset int) (uint, int, error)

ChunkForOffset returns the chunk containing data beginning at offset. Returns chunk-number, offset inside this chunk, error.

func (*Archive) IndexOfChunk ΒΆ

func (arc *Archive) IndexOfChunk(chunkNum uint) (int, error)

IndexOfChunk returns the slice-index for a specific chunk number.

type ArchiveResult ΒΆ

type ArchiveResult struct {
	Archive *Archive
	Error   error
}

ArchiveResult wraps Archive and an error. Either Archive or Error is nil.

type Backend ΒΆ

type Backend interface {
	// Location returns the type and location of the repository
	Location() string

	// Protocols returns the Protocol Schemes supported by this backend
	Protocols() []string

	// Description returns a user-friendly description for this backend
	Description() string

	// Close the backend
	Close() error

	// AvailableSpace returns the free space in bytes on this backend
	AvailableSpace() (uint64, error)

	// LoadChunk loads a single Chunk
	LoadChunk(shasum string, part, totalParts uint) ([]byte, error)
	// StoreChunk stores a single Chunk
	StoreChunk(shasum string, part, totalParts uint, data []byte) (uint64, error)
	// DeleteChunk deletes a single Chunk
	DeleteChunk(shasum string, part, totalParts uint) error

	// LoadSnapshot loads a snapshot
	LoadSnapshot(id string) ([]byte, error)
	// SaveSnapshot stores a snapshot
	SaveSnapshot(id string, data []byte) error

	// LoadChunkIndex loads the chunk-index
	LoadChunkIndex() ([]byte, error)
	// SaveChunkIndex stores the chunk-index
	SaveChunkIndex(data []byte) error

	// InitRepository creates a new repository
	InitRepository() error
	// LoadRepository reads the metadata for a repository
	LoadRepository() ([]byte, error)
	// SaveRepository stores the metadata for a repository
	SaveRepository(data []byte) error
}

Backend is used to store and access data.

func BackendFromURL ΒΆ

func BackendFromURL(path string) (Backend, error)

BackendFromURL returns the matching backend for path.

type BackendFactory ΒΆ

type BackendFactory interface {
	NewBackend(url url.URL) (Backend, error)
	Protocols() []string
}

BackendFactory is used to initialize a new backend.

type BackendFilesystem ΒΆ

type BackendFilesystem interface {
	// Stat stats a file on disk
	Stat(path string) (uint64, error)
	// CreatePath creates a dir including all its parents dirs, when required
	CreatePath(path string) error
	// ReadFile reads a file from disk
	ReadFile(path string) ([]byte, error)
	// WriteFile writes a file to disk
	WriteFile(path string, data []byte) (uint64, error)
	// DeleteFile deletes a file from disk
	DeleteFile(path string) error
}

BackendFilesystem is used to store and access data on a filesytem based backend.

type BackendManager ΒΆ

type BackendManager struct {
	Backends []*Backend
	// contains filtered or unexported fields
}

BackendManager stores data on multiple backends.

func (*BackendManager) AddBackend ΒΆ

func (backend *BackendManager) AddBackend(be *Backend)

AddBackend adds a backend.

func (*BackendManager) DeleteChunk ΒΆ

func (backend *BackendManager) DeleteChunk(shasum string, part, totalParts uint) error

DeleteChunk deletes a single Chunk.

func (*BackendManager) InitRepository ΒΆ

func (backend *BackendManager) InitRepository() error

InitRepository creates a new repository.

func (*BackendManager) LoadChunk ΒΆ

func (backend *BackendManager) LoadChunk(chunk Chunk, part uint) ([]byte, error)

LoadChunk loads a Chunk from backends.

func (*BackendManager) LoadChunkIndex ΒΆ

func (backend *BackendManager) LoadChunkIndex() ([]byte, error)

LoadChunkIndex loads the chunk-index.

func (*BackendManager) LoadRepository ΒΆ

func (backend *BackendManager) LoadRepository() ([]byte, error)

LoadRepository reads the metadata for a repository.

func (*BackendManager) LoadSnapshot ΒΆ

func (backend *BackendManager) LoadSnapshot(id string) ([]byte, error)

LoadSnapshot loads a snapshot.

func (*BackendManager) Locations ΒΆ

func (backend *BackendManager) Locations() []string

Locations returns the urls for all backends.

func (*BackendManager) SaveChunkIndex ΒΆ

func (backend *BackendManager) SaveChunkIndex(b []byte) error

SaveChunkIndex stores the chunk-index on all storage backends.

func (*BackendManager) SaveRepository ΒΆ

func (backend *BackendManager) SaveRepository(b []byte) error

SaveRepository stores the metadata for a repository.

func (*BackendManager) SaveSnapshot ΒΆ

func (backend *BackendManager) SaveSnapshot(id string, b []byte) error

SaveSnapshot stores a snapshot on all storage backends.

func (*BackendManager) StoreChunk ΒΆ

func (backend *BackendManager) StoreChunk(chunk Chunk) (size uint64, err error)

StoreChunk stores a single Chunk on backends.

type CheckSumError ΒΆ

type CheckSumError struct {
	Method           string
	ExpectedCheckSum string
	FoundCheckSum    string
}

CheckSumError records an error and the calculated checksums that did not match.

func (*CheckSumError) Error ΒΆ

func (e *CheckSumError) Error() string

type Chunk ΒΆ

type Chunk struct {
	Data          *[][]byte `json:"-"`
	DataParts     uint      `json:"data_parts"`
	ParityParts   uint      `json:"parity_parts"`
	OriginalSize  int       `json:"original_size"`
	Size          int       `json:"size"`
	DecryptedHash string    `json:"decrypted_hash"`
	Hash          string    `json:"hash"`
	Num           uint      `json:"num"`
}

Chunk stores an encrypted chunk alongside with its metadata.

type ChunkError ΒΆ

type ChunkError struct {
	ChunkNum uint
}

ChunkError records an error and the index that caused it.

func (*ChunkError) Error ΒΆ

func (e *ChunkError) Error() string

type ChunkIndex ΒΆ

type ChunkIndex struct {
	Chunks map[string]*ChunkIndexItem `json:"chunks"`
}

A ChunkIndex links chunks with snapshots.

func OpenChunkIndex ΒΆ

func OpenChunkIndex(repository *Repository) (ChunkIndex, error)

OpenChunkIndex opens an existing chunkindex.

func (*ChunkIndex) AddArchive ΒΆ

func (index *ChunkIndex) AddArchive(archive *Archive, snapshot string)

AddArchive updates chunk-index with the new chunks.

func (*ChunkIndex) Pack ΒΆ

func (index *ChunkIndex) Pack(repository *Repository) (freedSize uint64, err error)

Pack deletes unreferenced chunks and removes them from the index.

func (*ChunkIndex) RemoveSnapshot ΒΆ

func (index *ChunkIndex) RemoveSnapshot(snapshot string)

RemoveSnapshot removes all references to snapshot from the chunk-index.

func (*ChunkIndex) Save ΒΆ

func (index *ChunkIndex) Save(repository *Repository) error

Save writes a chunk-index.

type ChunkIndexItem ΒΆ

type ChunkIndexItem struct {
	Hash        string   `json:"hash"`
	DataParts   uint     `json:"data_parts"`
	ParityParts uint     `json:"parity_parts"`
	Size        int      `json:"size"`
	Snapshots   []string `json:"snapshots"`
}

A ChunkIndexItem links a chunk with one or many snapshots.

type ChunkResult ΒΆ

type ChunkResult struct {
	Chunk Chunk
	Error error
}

ChunkResult is used to transfer either a chunk or an error down the channel.

type Compressor ΒΆ

type Compressor struct {
	Method uint16
}

Compressor is a pipeline processor that compresses data.

func (Compressor) Process ΒΆ

func (c Compressor) Process(data []byte) ([]byte, error)

Process compresses the data.

type DataReconstructionError ΒΆ

type DataReconstructionError struct {
	Chunk          Chunk
	BlocksFound    uint
	FailedBackends uint
}

DataReconstructionError records an error and the associated parity information.

func (*DataReconstructionError) Error ΒΆ

func (e *DataReconstructionError) Error() string

type Decompressor ΒΆ

type Decompressor struct {
	Method uint16
}

Decompressor is a pipeline processor that decompresses data.

func (Decompressor) Process ΒΆ

func (c Decompressor) Process(data []byte) ([]byte, error)

Process decompresses the data.

type Decryptor ΒΆ

type Decryptor struct {
	Method uint16
	// contains filtered or unexported fields
}

Decryptor is a pipeline processor that decrypts data.

func NewDecryptor ΒΆ

func NewDecryptor(method uint16, password string) (Decryptor, error)

NewDecryptor returns a newly configured Decryptor.

func (Decryptor) Process ΒΆ

func (e Decryptor) Process(data []byte) ([]byte, error)

Process decrypts the data.

type Encryptor ΒΆ

type Encryptor struct {
	Method uint16
	// contains filtered or unexported fields
}

Encryptor is a pipeline processor that encrypts data.

func NewEncryptor ΒΆ

func NewEncryptor(method uint16, password string) (Encryptor, error)

NewEncryptor returns a newly configured Encryptor.

func (Encryptor) Process ΒΆ

func (e Encryptor) Process(data []byte) ([]byte, error)

Process encrypts the data.

type LogLevel ΒΆ

type LogLevel int

log levels for logging.

func (LogLevel) String ΒΆ

func (l LogLevel) String() string

type Logger ΒΆ

type Logger interface {
	Fatal(v ...interface{})
	Fatalf(format string, v ...interface{})
	Warn(v ...interface{})
	Warnf(format string, v ...interface{})
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Info(v ...interface{})
	Infof(format string, v ...interface{})
	Debug(v ...interface{})
	Debugf(format string, v ...interface{})
}

Logger is used for levelled logging and verbose flag.

type NopLogger ΒΆ

type NopLogger struct {
}

The quiet NopLogger will be used by default if no logger has been set via SetLogger().

func (NopLogger) Debug ΒΆ

func (nl NopLogger) Debug(v ...interface{})

func (NopLogger) Debugf ΒΆ

func (nl NopLogger) Debugf(format string, v ...interface{})

func (NopLogger) Fatal ΒΆ

func (nl NopLogger) Fatal(v ...interface{})

func (NopLogger) Fatalf ΒΆ

func (nl NopLogger) Fatalf(format string, v ...interface{})

func (NopLogger) Info ΒΆ

func (nl NopLogger) Info(v ...interface{})

func (NopLogger) Infof ΒΆ

func (nl NopLogger) Infof(format string, v ...interface{})

func (NopLogger) Print ΒΆ

func (nl NopLogger) Print(v ...interface{})

func (NopLogger) Printf ΒΆ

func (nl NopLogger) Printf(format string, v ...interface{})

func (NopLogger) Warn ΒΆ

func (nl NopLogger) Warn(v ...interface{})

func (NopLogger) Warnf ΒΆ

func (nl NopLogger) Warnf(format string, v ...interface{})

type Pipeline ΒΆ

type Pipeline struct {
	Processors []PipelineProcessor
}

Pipeline passes data through various steps (for compression, encryption etc).

func NewDecodingPipeline ΒΆ

func NewDecodingPipeline(compression, encryption uint16, password string) (Pipeline, error)

NewDecodingPipeline returns a new pipeline consisting of a decryptor and a decompressor.

func NewEncodingPipeline ΒΆ

func NewEncodingPipeline(compression, encryption uint16, password string) (Pipeline, error)

NewEncodingPipeline returns a new pipeline consisting of a compressor and an encryptor.

func (*Pipeline) Decode ΒΆ

func (p *Pipeline) Decode(b []byte, data interface{}) error

Decode sends the data through all configured processors and gob-decodes the result.

func (*Pipeline) Encode ΒΆ

func (p *Pipeline) Encode(data interface{}) ([]byte, error)

Encode gob-encodes an object and sends the data through all configured processors and returns the result.

func (*Pipeline) Process ΒΆ

func (p *Pipeline) Process(data []byte) ([]byte, error)

Process sends the data through all configured processors and returns the result.

type PipelineProcessor ΒΆ

type PipelineProcessor interface {
	Process(data []byte) ([]byte, error)
}

PipelineProcessor is a simple interface to process data.

type Progress ΒΆ

type Progress struct {
	Path             string
	Timer            time.Time
	CurrentItemStats Stats
	TotalStatistics  Stats
	Error            error
}

Progress contains stats and current path.

func (Progress) TransferSpeed ΒΆ

func (p Progress) TransferSpeed() uint64

TransferSpeed returns the average transfer speed in bytes per second.

type Repository ΒΆ

type Repository struct {
	Version uint      `json:"version"`
	Volumes []*Volume `json:"volumes"`
	Paths   []string  `json:"storage"`
	Key     string    `json:"key"` // key for encrypting data stored with knoxite
	// contains filtered or unexported fields
}

A Repository is a collection of backup snapshots.

func NewRepository ΒΆ

func NewRepository(path, password string) (Repository, error)

NewRepository returns a new repository.

func OpenRepository ΒΆ

func OpenRepository(path, password string) (Repository, error)

OpenRepository opens an existing repository and migrates it if possible.

func (*Repository) AddVolume ΒΆ

func (r *Repository) AddVolume(volume *Volume) error

AddVolume adds a volume to a repository.

func (*Repository) BackendManager ΒΆ

func (r *Repository) BackendManager() *BackendManager

BackendManager returns the repository's BackendManager.

func (*Repository) ChangeLocation ΒΆ

func (r *Repository) ChangeLocation(oldLocation, newLocation string) error

func (*Repository) ChangePassword ΒΆ

func (r *Repository) ChangePassword(newPassword string) error

Changes password of repository.

func (*Repository) FindSnapshot ΒΆ

func (r *Repository) FindSnapshot(id string) (*Volume, *Snapshot, error)

FindSnapshot finds a snapshot within a repository.

func (*Repository) FindVolume ΒΆ

func (r *Repository) FindVolume(id string) (*Volume, error)

FindVolume finds a volume within a repository.

func (*Repository) IsEmpty ΒΆ

func (r *Repository) IsEmpty() bool

IsEmpty returns true if there a no snapshots stored in a repository.

func (*Repository) Migrate ΒΆ

func (r *Repository) Migrate() error

Migrates a repository to the current version, if possible.

func (*Repository) RemoveVolume ΒΆ

func (r *Repository) RemoveVolume(volume *Volume) error

RemoveVolume removes a volume from a repository.

func (*Repository) Save ΒΆ

func (r *Repository) Save() error

Save writes a repository's metadata.

type SeekError ΒΆ

type SeekError struct {
	Offset int
}

SeekError records an error and the offset that caused it.

func (*SeekError) Error ΒΆ

func (e *SeekError) Error() string

type Snapshot ΒΆ

type Snapshot struct {
	ID          string              `json:"id"`
	Date        time.Time           `json:"date"`
	Description string              `json:"description"`
	Stats       Stats               `json:"stats"`
	Archives    map[string]*Archive `json:"items"`
	// contains filtered or unexported fields
}

A Snapshot is a compilation of one or many archives.

func NewSnapshot ΒΆ

func NewSnapshot(description string) (*Snapshot, error)

NewSnapshot creates a new snapshot.

func (*Snapshot) Add ΒΆ

func (snapshot *Snapshot) Add(repository Repository, chunkIndex *ChunkIndex, opts StoreOptions) <-chan Progress

Add adds a path to a Snapshot.

func (*Snapshot) AddArchive ΒΆ

func (snapshot *Snapshot) AddArchive(archive *Archive)

AddArchive adds an archive to a snapshot.

func (*Snapshot) Clone ΒΆ

func (snapshot *Snapshot) Clone() (*Snapshot, error)

Clone clones a snapshot.

func (*Snapshot) Save ΒΆ

func (snapshot *Snapshot) Save(repository *Repository) error

Save writes a snapshot's metadata.

type Stats ΒΆ

type Stats struct {
	Files       uint64 `json:"files"`
	Dirs        uint64 `json:"dirs"`
	SymLinks    uint64 `json:"symlinks"`
	Size        uint64 `json:"size"`
	StorageSize uint64 `json:"stored_size"`
	Transferred uint64 `json:"transferred"`
	Errors      uint64 `json:"errors"`
}

Stats contains a bunch of Stats counters.

func DecodeArchiveData ΒΆ

func DecodeArchiveData(repository Repository, arc Archive) ([]byte, Stats, error)

DecodeArchiveData returns the content of a single archive.

func (*Stats) Add ΒΆ

func (s *Stats) Add(other Stats)

Add accumulates other into s.

func (Stats) String ΒΆ

func (s Stats) String() string

String returns human-readable Stats.

type StorageFilesystem ΒΆ

type StorageFilesystem struct {
	Path string
	// contains filtered or unexported fields
}

StorageFilesystem is bridging a BackendFilesystem to a Backend interface.

func NewStorageFilesystem ΒΆ

func NewStorageFilesystem(path string, storage BackendFilesystem) (StorageFilesystem, error)

NewStorageFilesystem returns a StorageFilesystem object.

func (StorageFilesystem) DeleteChunk ΒΆ

func (backend StorageFilesystem) DeleteChunk(shasum string, part, totalParts uint) error

DeleteChunk deletes a single Chunk.

func (StorageFilesystem) InitRepository ΒΆ

func (backend StorageFilesystem) InitRepository() error

InitRepository creates a new repository.

func (StorageFilesystem) LoadChunk ΒΆ

func (backend StorageFilesystem) LoadChunk(shasum string, part, totalParts uint) ([]byte, error)

LoadChunk loads a Chunk from disk.

func (StorageFilesystem) LoadChunkIndex ΒΆ

func (backend StorageFilesystem) LoadChunkIndex() ([]byte, error)

LoadChunkIndex reads the chunk-index.

func (StorageFilesystem) LoadRepository ΒΆ

func (backend StorageFilesystem) LoadRepository() ([]byte, error)

LoadRepository reads the metadata for a repository.

func (StorageFilesystem) LoadSnapshot ΒΆ

func (backend StorageFilesystem) LoadSnapshot(id string) ([]byte, error)

LoadSnapshot loads a snapshot.

func (StorageFilesystem) SaveChunkIndex ΒΆ

func (backend StorageFilesystem) SaveChunkIndex(b []byte) error

SaveChunkIndex stores the chunk-index.

func (StorageFilesystem) SaveRepository ΒΆ

func (backend StorageFilesystem) SaveRepository(b []byte) error

SaveRepository stores the metadata for a repository.

func (StorageFilesystem) SaveSnapshot ΒΆ

func (backend StorageFilesystem) SaveSnapshot(id string, b []byte) error

SaveSnapshot stores a snapshot.

func (StorageFilesystem) StoreChunk ΒΆ

func (backend StorageFilesystem) StoreChunk(shasum string, part, totalParts uint, data []byte) (size uint64, err error)

StoreChunk stores a single Chunk on disk.

type StorageLocal ΒΆ

type StorageLocal struct {
	StorageFilesystem
}

StorageLocal stores data on the local disk.

func (*StorageLocal) AvailableSpace ΒΆ

func (backend *StorageLocal) AvailableSpace() (uint64, error)

AvailableSpace returns the free space on this backend.

func (*StorageLocal) Close ΒΆ

func (backend *StorageLocal) Close() error

Close the backend.

func (*StorageLocal) CreatePath ΒΆ

func (backend *StorageLocal) CreatePath(path string) error

CreatePath creates a dir including all its parents dirs, when required.

func (StorageLocal) DeleteFile ΒΆ

func (backend StorageLocal) DeleteFile(path string) error

DeleteFile deletes a file from disk.

func (*StorageLocal) Description ΒΆ

func (backend *StorageLocal) Description() string

Description returns a user-friendly description for this backend.

func (*StorageLocal) Location ΒΆ

func (backend *StorageLocal) Location() string

Location returns the type and location of the repository.

func (*StorageLocal) NewBackend ΒΆ

func (*StorageLocal) NewBackend(u url.URL) (Backend, error)

NewBackend returns a StorageLocal backend.

func (*StorageLocal) Protocols ΒΆ

func (backend *StorageLocal) Protocols() []string

Protocols returns the Protocol Schemes supported by this backend.

func (StorageLocal) ReadFile ΒΆ

func (backend StorageLocal) ReadFile(path string) ([]byte, error)

ReadFile reads a file from disk.

func (StorageLocal) Stat ΒΆ

func (backend StorageLocal) Stat(path string) (uint64, error)

Stat stats a file on disk.

func (StorageLocal) WriteFile ΒΆ

func (backend StorageLocal) WriteFile(path string, data []byte) (size uint64, err error)

WriteFile writes a file to disk.

type StoreOptions ΒΆ

type StoreOptions struct {
	CWD         string
	Paths       []string
	Excludes    []string
	Compress    uint16
	Encrypt     uint16
	Pedantic    bool
	DataParts   uint
	ParityParts uint
}

StoreOptions holds all the storage settings for a snapshot operation.

type Volume ΒΆ

type Volume struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Snapshots   []string `json:"snapshots"`
}

A Volume contains various snapshots.

func NewVolume ΒΆ

func NewVolume(name, description string) (*Volume, error)

NewVolume creates a new volume.

func (*Volume) AddSnapshot ΒΆ

func (v *Volume) AddSnapshot(id string) error

AddSnapshot adds a snapshot to a volume.

func (*Volume) LoadSnapshot ΒΆ

func (v *Volume) LoadSnapshot(id string, repository *Repository) (*Snapshot, error)

LoadSnapshot loads a snapshot within a volume from a repository.

func (*Volume) RemoveSnapshot ΒΆ

func (v *Volume) RemoveSnapshot(id string) error

RemoveSnapshot removes a snapshot from a volume.

Directories ΒΆ

Path Synopsis
cmd
knoxite
* knoxite * Copyright (c) 2020, Nicolas Martin <penguwin@penguwin.eu> * * For license see LICENSE
* knoxite * Copyright (c) 2020, Nicolas Martin <penguwin@penguwin.eu> * * For license see LICENSE
knoxite/config
* knoxite * Copyright (c) 2020, Nicolas Martin <penguwin@penguwin.eu> * 2020, Sergio Rubio <sergio@rubio.im> * * For license see LICENSE
* knoxite * Copyright (c) 2020, Nicolas Martin <penguwin@penguwin.eu> * 2020, Sergio Rubio <sergio@rubio.im> * * For license see LICENSE
ftp
s3

Jump to

Keyboard shortcuts

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