mirror of
https://github.com/octoleo/restic.git
synced 2024-12-01 09:13:56 +00:00
Fix incremental backup
Copying blobs (for unchanged files and subtrees) from old BlobList to new BlobList was missing
This commit is contained in:
parent
4b070358ef
commit
33bcf31bae
@ -32,7 +32,7 @@ type Archiver struct {
|
|||||||
p *Progress
|
p *Progress
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewArchiver(s Server, p *Progress) (*Archiver, error) {
|
func NewArchiver(s Server, bl *BlobList, p *Progress) (*Archiver, error) {
|
||||||
var err error
|
var err error
|
||||||
arch := &Archiver{
|
arch := &Archiver{
|
||||||
s: s,
|
s: s,
|
||||||
@ -56,6 +56,9 @@ func NewArchiver(s Server, p *Progress) (*Archiver, error) {
|
|||||||
arch.Filter = func(string, os.FileInfo) bool { return true }
|
arch.Filter = func(string, os.FileInfo) bool { return true }
|
||||||
|
|
||||||
arch.bl = NewBlobList()
|
arch.bl = NewBlobList()
|
||||||
|
if bl != nil {
|
||||||
|
arch.bl.Merge(bl)
|
||||||
|
}
|
||||||
arch.ch = NewContentHandler(s)
|
arch.ch = NewContentHandler(s)
|
||||||
|
|
||||||
// load all blobs from all snapshots
|
// load all blobs from all snapshots
|
||||||
|
@ -120,6 +120,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bl *restic.BlobList
|
||||||
if parentSnapshotID != nil {
|
if parentSnapshotID != nil {
|
||||||
fmt.Printf("load old snapshot\n")
|
fmt.Printf("load old snapshot\n")
|
||||||
ch := restic.NewContentHandler(s)
|
ch := restic.NewContentHandler(s)
|
||||||
@ -133,7 +134,11 @@ func (cmd CmdBackup) Execute(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
newTree.CopyFrom(oldTree)
|
bl = restic.NewBlobList()
|
||||||
|
err = newTree.CopyFrom(bl, oldTree, ch.BlobList())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
archiveProgress := restic.NewProgress(time.Second)
|
archiveProgress := restic.NewProgress(time.Second)
|
||||||
@ -170,7 +175,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
arch, err := restic.NewArchiver(s, archiveProgress)
|
arch, err := restic.NewArchiver(s, bl, archiveProgress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "err: %v\n", err)
|
fmt.Fprintf(os.Stderr, "err: %v\n", err)
|
||||||
}
|
}
|
||||||
|
27
tree.go
27
tree.go
@ -120,7 +120,7 @@ func LoadTreeRecursive(path string, ch *ContentHandler, id backend.ID) (Tree, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CopyFrom recursively copies all content from other to t.
|
// CopyFrom recursively copies all content from other to t.
|
||||||
func (t Tree) CopyFrom(other Tree) {
|
func (t Tree) CopyFrom(bl *BlobList, other Tree, otherBl *BlobList) error {
|
||||||
for _, node := range t {
|
for _, node := range t {
|
||||||
// only process files and dirs
|
// only process files and dirs
|
||||||
if node.Type != "file" && node.Type != "dir" {
|
if node.Type != "file" && node.Type != "dir" {
|
||||||
@ -140,18 +140,41 @@ func (t Tree) CopyFrom(other Tree) {
|
|||||||
if node.SameContent(oldNode) {
|
if node.SameContent(oldNode) {
|
||||||
// copy Content
|
// copy Content
|
||||||
node.Content = oldNode.Content
|
node.Content = oldNode.Content
|
||||||
|
|
||||||
|
// copy storage IDs
|
||||||
|
for _, id := range node.Content {
|
||||||
|
blob, err := otherBl.Find(Blob{ID: id})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bl.Insert(blob)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// fill in all subtrees from old subtree
|
// fill in all subtrees from old subtree
|
||||||
node.tree.CopyFrom(*oldNode.tree)
|
err := node.tree.CopyFrom(bl, *oldNode.tree, otherBl)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// check if tree has changed
|
// check if tree has changed
|
||||||
if node.tree.Equals(*oldNode.tree) {
|
if node.tree.Equals(*oldNode.tree) {
|
||||||
// if nothing has changed, copy subtree ID
|
// if nothing has changed, copy subtree ID
|
||||||
node.Subtree = oldNode.Subtree
|
node.Subtree = oldNode.Subtree
|
||||||
|
|
||||||
|
// and store blob in bloblist
|
||||||
|
blob, err := otherBl.Find(Blob{ID: oldNode.Subtree})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bl.Insert(blob)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equals returns true if t and other have exactly the same nodes.
|
// Equals returns true if t and other have exactly the same nodes.
|
||||||
|
Loading…
Reference in New Issue
Block a user