mirror of
https://github.com/octoleo/restic.git
synced 2024-11-29 00:06:32 +00:00
Save blobs from parent snapshot to new snapshot
This commit is contained in:
parent
0ac1716463
commit
caf00f6087
46
archiver.go
46
archiver.go
@ -27,6 +27,7 @@ type Archiver struct {
|
|||||||
ch *ContentHandler
|
ch *ContentHandler
|
||||||
|
|
||||||
bl *BlobList // blobs used for the current snapshot
|
bl *BlobList // blobs used for the current snapshot
|
||||||
|
parentBl *BlobList // blobs from the parent snapshot
|
||||||
|
|
||||||
fileToken chan struct{}
|
fileToken chan struct{}
|
||||||
blobToken chan struct{}
|
blobToken chan struct{}
|
||||||
@ -249,6 +250,30 @@ func (arch *Archiver) SaveFile(node *Node) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (arch *Archiver) populateFromOldTree(tree, oldTree Tree) error {
|
||||||
|
// update content from old tree
|
||||||
|
err := tree.PopulateFrom(oldTree)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// add blobs to bloblist
|
||||||
|
for _, node := range tree {
|
||||||
|
if node.Content != nil {
|
||||||
|
for _, blobID := range node.Content {
|
||||||
|
blob, err := arch.parentBl.Find(Blob{ID: blobID})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
arch.bl.Insert(blob)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (arch *Archiver) loadTree(dir string, oldTreeID backend.ID) (*Tree, error) {
|
func (arch *Archiver) loadTree(dir string, oldTreeID backend.ID) (*Tree, error) {
|
||||||
var (
|
var (
|
||||||
oldTree Tree
|
oldTree Tree
|
||||||
@ -316,7 +341,7 @@ func (arch *Archiver) loadTree(dir string, oldTreeID backend.ID) (*Tree, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// populate with content from oldTree
|
// populate with content from oldTree
|
||||||
err = tree.PopulateFrom(oldTree)
|
err = arch.populateFromOldTree(tree, oldTree)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -342,12 +367,12 @@ func (arch *Archiver) loadTree(dir string, oldTreeID backend.ID) (*Tree, error)
|
|||||||
return &tree, nil
|
return &tree, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (arch *Archiver) LoadTree(path string, baseSnapshot backend.ID) (*Tree, error) {
|
func (arch *Archiver) LoadTree(path string, parentSnapshot backend.ID) (*Tree, error) {
|
||||||
var oldTree Tree
|
var oldTree Tree
|
||||||
|
|
||||||
if baseSnapshot != nil {
|
if parentSnapshot != nil {
|
||||||
// load old tree from snapshot
|
// load old tree from snapshot
|
||||||
snapshot, err := arch.ch.LoadSnapshot(baseSnapshot)
|
snapshot, err := LoadSnapshot(arch.ch, parentSnapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, arrar.Annotate(err, "load old snapshot")
|
return nil, arrar.Annotate(err, "load old snapshot")
|
||||||
}
|
}
|
||||||
@ -356,6 +381,12 @@ func (arch *Archiver) LoadTree(path string, baseSnapshot backend.ID) (*Tree, err
|
|||||||
return nil, errors.New("snapshot without tree!")
|
return nil, errors.New("snapshot without tree!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load old bloblist from snapshot
|
||||||
|
arch.parentBl, err = LoadBlobList(arch.ch, snapshot.Map)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
oldTree, err = LoadTree(arch.ch, snapshot.Content)
|
oldTree, err = LoadTree(arch.ch, snapshot.Content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, arrar.Annotate(err, "load old tree")
|
return nil, arrar.Annotate(err, "load old tree")
|
||||||
@ -380,8 +411,11 @@ func (arch *Archiver) LoadTree(path string, baseSnapshot backend.ID) (*Tree, err
|
|||||||
if node.Type != "dir" {
|
if node.Type != "dir" {
|
||||||
t := &Tree{node}
|
t := &Tree{node}
|
||||||
|
|
||||||
// compare with old tree
|
// populate with content from oldTree
|
||||||
t.PopulateFrom(oldTree)
|
err = arch.populateFromOldTree(*t, oldTree)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// if no old node has been found, update stats
|
// if no old node has been found, update stats
|
||||||
if node.Content == nil && node.Subtree == nil {
|
if node.Content == nil && node.Subtree == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user