Compare commits
1 Commits
main
...
feature/re
| Author | SHA1 | Date | |
|---|---|---|---|
| 4345da2f0c |
@ -111,26 +111,59 @@ func (v *Vaultik) Restore(opts *RestoreOptions) error {
|
|||||||
result := &RestoreResult{}
|
result := &RestoreResult{}
|
||||||
blobCache := make(map[string][]byte) // Cache downloaded and decrypted blobs
|
blobCache := make(map[string][]byte) // Cache downloaded and decrypted blobs
|
||||||
|
|
||||||
for i, file := range files {
|
// Calculate total bytes for progress bar
|
||||||
|
var totalBytes int64
|
||||||
|
for _, file := range files {
|
||||||
|
totalBytes += file.Size
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _ = fmt.Fprintf(v.Stdout, "Restoring %d files (%s)...\n",
|
||||||
|
len(files),
|
||||||
|
humanize.Bytes(uint64(totalBytes)),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Create progress bar if output is a terminal
|
||||||
|
var bar *progressbar.ProgressBar
|
||||||
|
if isTerminal() {
|
||||||
|
bar = progressbar.NewOptions64(
|
||||||
|
totalBytes,
|
||||||
|
progressbar.OptionSetDescription("Restoring"),
|
||||||
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
|
progressbar.OptionShowBytes(true),
|
||||||
|
progressbar.OptionShowCount(),
|
||||||
|
progressbar.OptionSetWidth(40),
|
||||||
|
progressbar.OptionThrottle(100*time.Millisecond),
|
||||||
|
progressbar.OptionOnCompletion(func() {
|
||||||
|
fmt.Fprint(os.Stderr, "\n")
|
||||||
|
}),
|
||||||
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
if v.ctx.Err() != nil {
|
if v.ctx.Err() != nil {
|
||||||
return v.ctx.Err()
|
return v.ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := v.restoreFile(v.ctx, repos, file, opts.TargetDir, identity, chunkToBlobMap, blobCache, result); err != nil {
|
if err := v.restoreFile(v.ctx, repos, file, opts.TargetDir, identity, chunkToBlobMap, blobCache, result); err != nil {
|
||||||
log.Error("Failed to restore file", "path", file.Path, "error", err)
|
log.Error("Failed to restore file", "path", file.Path, "error", err)
|
||||||
// Continue with other files
|
// Update progress bar even on failure
|
||||||
|
if bar != nil {
|
||||||
|
_ = bar.Add64(file.Size)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Progress logging
|
// Update progress bar
|
||||||
if (i+1)%100 == 0 || i+1 == len(files) {
|
if bar != nil {
|
||||||
log.Info("Restore progress",
|
_ = bar.Add64(file.Size)
|
||||||
"files", fmt.Sprintf("%d/%d", i+1, len(files)),
|
|
||||||
"bytes", humanize.Bytes(uint64(result.BytesRestored)),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if bar != nil {
|
||||||
|
_ = bar.Finish()
|
||||||
|
}
|
||||||
|
|
||||||
result.Duration = time.Since(startTime)
|
result.Duration = time.Since(startTime)
|
||||||
|
|
||||||
log.Info("Restore complete",
|
log.Info("Restore complete",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user