mirror of
https://github.com/restic/restic.git
synced 2025-10-27 08:01:14 +00:00
Cache blobs for each snapshot
This commit is contained in:
@@ -91,44 +91,6 @@ func newScanProgress() *restic.Progress {
|
||||
return p
|
||||
}
|
||||
|
||||
func newLoadBlobsProgress(s restic.Server) (*restic.Progress, error) {
|
||||
if !terminal.IsTerminal(int(os.Stdout.Fd())) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
trees, err := s.Count(backend.Tree)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
eta := uint64(0)
|
||||
tps := uint64(0) // trees per second
|
||||
|
||||
p := restic.NewProgress(time.Second)
|
||||
p.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||
sec := uint64(d / time.Second)
|
||||
if trees > 0 && sec > 0 && ticker {
|
||||
tps = uint64(s.Trees) / sec
|
||||
if tps > 0 {
|
||||
eta = (uint64(trees) - s.Trees) / tps
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("\x1b[2K\r[%s] %3.2f%% %d trees/s %d / %d trees, %d blobs ETA %s",
|
||||
format_duration(d),
|
||||
float64(s.Trees)/float64(trees)*100,
|
||||
tps,
|
||||
s.Trees, trees,
|
||||
s.Blobs,
|
||||
format_seconds(eta))
|
||||
}
|
||||
p.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||
fmt.Printf("\nDone in %s\n", format_duration(d))
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func newArchiveProgress(todo restic.Stat) *restic.Progress {
|
||||
if !terminal.IsTerminal(int(os.Stdout.Fd())) {
|
||||
return nil
|
||||
@@ -218,12 +180,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
||||
}
|
||||
|
||||
fmt.Printf("loading blobs\n")
|
||||
pb, err := newLoadBlobsProgress(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = arch.Preload(pb)
|
||||
err = arch.Preload()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
"github.com/restic/restic"
|
||||
@@ -49,7 +50,7 @@ func (cmd CmdCache) Execute(args []string) error {
|
||||
treeCh := make(chan backend.ID)
|
||||
worker := func(wg *sync.WaitGroup, ch chan backend.ID) {
|
||||
for treeID := range ch {
|
||||
cached, err := cache.Has(backend.Tree, treeID)
|
||||
cached, err := cache.Has(backend.Tree, "", treeID)
|
||||
if err != nil {
|
||||
fmt.Printf("tree %v cache error: %v\n", treeID.Str(), err)
|
||||
continue
|
||||
@@ -72,12 +73,18 @@ func (cmd CmdCache) Execute(args []string) error {
|
||||
continue
|
||||
}
|
||||
|
||||
err = cache.Store(backend.Tree, treeID, decRd)
|
||||
wr, err := cache.Store(backend.Tree, "", treeID)
|
||||
if err != nil {
|
||||
fmt.Printf(" store error: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
_, err = io.Copy(wr, decRd)
|
||||
if err != nil {
|
||||
fmt.Printf(" Copy error: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = decRd.Close()
|
||||
if err != nil {
|
||||
fmt.Printf(" close error: %v\n", err)
|
||||
|
||||
Reference in New Issue
Block a user