2016-08-31 17:10:10 +00:00
|
|
|
package restic
|
|
|
|
|
2017-06-03 15:39:57 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2017-07-23 12:21:03 +00:00
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
"github.com/restic/restic/internal/backend"
|
2017-07-23 12:21:03 +00:00
|
|
|
"github.com/restic/restic/internal/crypto"
|
2023-01-14 15:04:14 +00:00
|
|
|
"github.com/restic/restic/internal/errors"
|
2022-05-26 10:49:03 +00:00
|
|
|
"github.com/restic/restic/internal/ui/progress"
|
2021-08-07 20:52:05 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2017-06-03 15:39:57 +00:00
|
|
|
)
|
2016-08-31 21:07:50 +00:00
|
|
|
|
2023-01-14 15:04:14 +00:00
|
|
|
// ErrInvalidData is used to report that a file is corrupted
|
|
|
|
var ErrInvalidData = errors.New("invalid data returned")
|
|
|
|
|
2016-08-31 17:10:10 +00:00
|
|
|
// Repository stores data in a backend. It provides high-level functions and
|
|
|
|
// transparently encrypts/decrypts data.
|
|
|
|
type Repository interface {
|
|
|
|
|
|
|
|
// Backend returns the backend used by the repository
|
2023-10-01 09:40:12 +00:00
|
|
|
Backend() backend.Backend
|
2021-08-07 22:38:17 +00:00
|
|
|
// Connections returns the maximum number of concurrent backend operations
|
|
|
|
Connections() uint
|
2016-08-31 17:10:10 +00:00
|
|
|
|
2016-08-31 21:07:50 +00:00
|
|
|
Key() *crypto.Key
|
|
|
|
|
2020-07-25 19:19:46 +00:00
|
|
|
Index() MasterIndex
|
2023-07-16 02:48:30 +00:00
|
|
|
LoadIndex(context.Context, *progress.Counter) error
|
2022-05-26 10:38:18 +00:00
|
|
|
SetIndex(MasterIndex) error
|
|
|
|
LookupBlobSize(ID, BlobType) (uint, bool)
|
2016-08-31 18:29:54 +00:00
|
|
|
|
|
|
|
Config() Config
|
2022-07-02 21:52:02 +00:00
|
|
|
PackSize() uint
|
2016-08-31 18:29:54 +00:00
|
|
|
|
2018-01-23 20:21:54 +00:00
|
|
|
// List calls the function fn for each file of type t in the repository.
|
|
|
|
// When an error is returned by fn, processing stops and List() returns the
|
|
|
|
// error.
|
|
|
|
//
|
|
|
|
// The function fn is called in the same Goroutine List() was called from.
|
|
|
|
List(ctx context.Context, t FileType, fn func(ID, int64) error) error
|
2020-11-16 03:03:45 +00:00
|
|
|
|
|
|
|
// ListPack returns the list of blobs saved in the pack id and the length of
|
2023-10-27 16:56:00 +00:00
|
|
|
// the pack header.
|
2020-11-16 03:03:45 +00:00
|
|
|
ListPack(context.Context, ID, int64) ([]Blob, uint32, error)
|
2016-09-01 20:42:12 +00:00
|
|
|
|
2022-06-12 12:38:19 +00:00
|
|
|
LoadBlob(context.Context, BlobType, ID, []byte) ([]byte, error)
|
2023-12-31 11:07:19 +00:00
|
|
|
LoadBlobsFromPack(ctx context.Context, packID ID, blobs []Blob, handleBlobFn func(blob BlobHandle, buf []byte, err error) error) error
|
2022-06-12 12:38:19 +00:00
|
|
|
SaveBlob(context.Context, BlobType, []byte, ID, bool) (ID, bool, int, error)
|
|
|
|
|
2021-08-07 20:52:05 +00:00
|
|
|
// StartPackUploader start goroutines to upload new pack files. The errgroup
|
|
|
|
// is used to immediately notify about an upload error. Flush() will also return
|
|
|
|
// that error.
|
|
|
|
StartPackUploader(ctx context.Context, wg *errgroup.Group)
|
2017-11-22 11:27:29 +00:00
|
|
|
Flush(context.Context) error
|
2016-09-01 20:42:12 +00:00
|
|
|
|
2023-01-27 14:01:54 +00:00
|
|
|
// LoadUnpacked loads and decrypts the file with the given type and ID.
|
|
|
|
LoadUnpacked(ctx context.Context, t FileType, id ID) (data []byte, err error)
|
2022-06-12 12:38:19 +00:00
|
|
|
SaveUnpacked(context.Context, FileType, []byte) (ID, error)
|
2016-08-31 18:29:54 +00:00
|
|
|
}
|
|
|
|
|
2023-10-01 09:40:12 +00:00
|
|
|
type FileType = backend.FileType
|
|
|
|
|
|
|
|
// These are the different data types a backend can store.
|
|
|
|
const (
|
|
|
|
PackFile FileType = backend.PackFile
|
|
|
|
KeyFile FileType = backend.KeyFile
|
|
|
|
LockFile FileType = backend.LockFile
|
|
|
|
SnapshotFile FileType = backend.SnapshotFile
|
|
|
|
IndexFile FileType = backend.IndexFile
|
|
|
|
ConfigFile FileType = backend.ConfigFile
|
|
|
|
)
|
2016-08-31 20:39:36 +00:00
|
|
|
|
2022-06-12 12:38:19 +00:00
|
|
|
// LoaderUnpacked allows loading a blob not stored in a pack file
|
|
|
|
type LoaderUnpacked interface {
|
2022-06-12 12:38:19 +00:00
|
|
|
// Connections returns the maximum number of concurrent backend operations
|
|
|
|
Connections() uint
|
2023-01-27 14:01:54 +00:00
|
|
|
LoadUnpacked(ctx context.Context, t FileType, id ID) (data []byte, err error)
|
2022-06-12 12:38:19 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 10:38:18 +00:00
|
|
|
// SaverUnpacked allows saving a blob not stored in a pack file
|
|
|
|
type SaverUnpacked interface {
|
2021-08-07 22:38:17 +00:00
|
|
|
// Connections returns the maximum number of concurrent backend operations
|
|
|
|
Connections() uint
|
2022-05-26 10:38:18 +00:00
|
|
|
SaveUnpacked(context.Context, FileType, []byte) (ID, error)
|
|
|
|
}
|
|
|
|
|
2021-08-20 08:09:34 +00:00
|
|
|
type PackBlobs struct {
|
|
|
|
PackID ID
|
|
|
|
Blobs []Blob
|
|
|
|
}
|
|
|
|
|
2024-01-20 14:58:06 +00:00
|
|
|
type MasterIndexSaveOpts struct {
|
|
|
|
SaveProgress *progress.Counter
|
|
|
|
DeleteProgress func() *progress.Counter
|
|
|
|
DeleteReport func(id ID, err error)
|
|
|
|
SkipDeletion bool
|
|
|
|
}
|
|
|
|
|
2020-07-25 19:19:46 +00:00
|
|
|
// MasterIndex keeps track of the blobs are stored within files.
|
|
|
|
type MasterIndex interface {
|
2020-11-05 21:18:00 +00:00
|
|
|
Has(BlobHandle) bool
|
|
|
|
Lookup(BlobHandle) []PackedBlob
|
2017-06-18 12:45:02 +00:00
|
|
|
|
2022-08-19 18:04:39 +00:00
|
|
|
// Each runs fn on all blobs known to the index. When the context is cancelled,
|
|
|
|
// the index iteration return immediately. This blocks any modification of the index.
|
|
|
|
Each(ctx context.Context, fn func(PackedBlob))
|
2021-08-20 08:09:34 +00:00
|
|
|
ListPacks(ctx context.Context, packs IDSet) <-chan PackBlobs
|
2022-05-26 10:49:03 +00:00
|
|
|
|
2024-01-20 14:58:06 +00:00
|
|
|
Save(ctx context.Context, repo Repository, excludePacks IDSet, extraObsolete IDs, opts MasterIndexSaveOpts) error
|
2016-08-31 18:29:54 +00:00
|
|
|
}
|
2023-10-01 11:05:56 +00:00
|
|
|
|
|
|
|
// Lister allows listing files in a backend.
|
|
|
|
type Lister interface {
|
|
|
|
List(ctx context.Context, t FileType, fn func(ID, int64) error) error
|
|
|
|
}
|
2024-01-19 21:44:50 +00:00
|
|
|
|
|
|
|
type ListerLoaderUnpacked interface {
|
|
|
|
Lister
|
|
|
|
LoaderUnpacked
|
|
|
|
}
|