mirror of
https://github.com/kopia/kopia.git
synced 2026-03-14 12:16:46 -04:00
This change removes lots of pointless string and custom format parsing code and instead relies on protobuf to do the thing. JSON is still an option thanks to proto3-generated output.
- Refactored ObjectID to use protobuf
- Indirect blocks to use protobuf (in the form of seek table)
- Added generic proto stream reader and writer
- ObjectIDFormat became proto enum
Also:
- fixed major issue where indirect object ID entries were not encrypted, since they were storing block IDs and not object IDs.
- dropped support for majority of formats, only supporting HMAC-{SHA256,SHA512,SHA512_384} hashes with AES256.
This produces object IDs of 32 or 64 characters long.
- changed how pretty-printing works for 'kopia show'
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package backup
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/kopia/kopia/fs"
|
|
"github.com/kopia/kopia/repo"
|
|
)
|
|
|
|
var (
|
|
zeroByte = []byte{0}
|
|
)
|
|
|
|
// Generator allows creation of backups.
|
|
type Generator interface {
|
|
Backup(m *Manifest, old *Manifest) error
|
|
}
|
|
|
|
type backupGenerator struct {
|
|
repo repo.Repository
|
|
}
|
|
|
|
func (bg *backupGenerator) Backup(m *Manifest, old *Manifest) error {
|
|
uploader := fs.NewUploader(bg.repo)
|
|
|
|
m.StartTime = time.Now()
|
|
var hashCacheID *repo.ObjectID
|
|
|
|
if old != nil {
|
|
hashCacheID = &old.HashCacheID
|
|
}
|
|
|
|
entry, err := fs.NewFilesystemEntry(m.Source, nil)
|
|
|
|
var r *fs.UploadResult
|
|
switch entry := entry.(type) {
|
|
case fs.Directory:
|
|
r, err = uploader.UploadDir(entry, hashCacheID)
|
|
case fs.File:
|
|
r, err = uploader.UploadFile(entry)
|
|
default:
|
|
return fmt.Errorf("unsupported source: %v", m.Source)
|
|
}
|
|
m.EndTime = time.Now()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
m.RootObjectID = r.ObjectID
|
|
m.HashCacheID = r.ManifestID
|
|
|
|
return nil
|
|
}
|
|
|
|
// NewGenerator creates new backup generator.
|
|
func NewGenerator(repo repo.Repository) (Generator, error) {
|
|
return &backupGenerator{
|
|
repo: repo,
|
|
}, nil
|
|
}
|