Compare commits
1 Commits
main
...
feat/resto
| Author | SHA1 | Date | |
|---|---|---|---|
| d2fb677aa3 |
@ -111,6 +111,30 @@ 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
|
||||||
|
|
||||||
|
// Calculate total bytes for progress bar
|
||||||
|
var totalBytesExpected int64
|
||||||
|
for _, file := range files {
|
||||||
|
totalBytesExpected += file.Size
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create progress bar if output is a terminal
|
||||||
|
var bar *progressbar.ProgressBar
|
||||||
|
if isTerminal() {
|
||||||
|
bar = progressbar.NewOptions64(
|
||||||
|
totalBytesExpected,
|
||||||
|
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 i, file := range files {
|
for i, file := range files {
|
||||||
if v.ctx.Err() != nil {
|
if v.ctx.Err() != nil {
|
||||||
return v.ctx.Err()
|
return v.ctx.Err()
|
||||||
@ -119,10 +143,14 @@ func (v *Vaultik) Restore(opts *RestoreOptions) error {
|
|||||||
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
|
// Continue with other files
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Progress logging
|
// Update progress bar
|
||||||
|
if bar != nil {
|
||||||
|
_ = bar.Add64(file.Size)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress logging (for non-terminal or structured logs)
|
||||||
if (i+1)%100 == 0 || i+1 == len(files) {
|
if (i+1)%100 == 0 || i+1 == len(files) {
|
||||||
log.Info("Restore progress",
|
log.Info("Restore progress",
|
||||||
"files", fmt.Sprintf("%d/%d", i+1, len(files)),
|
"files", fmt.Sprintf("%d/%d", i+1, len(files)),
|
||||||
@ -131,6 +159,10 @@ func (v *Vaultik) Restore(opts *RestoreOptions) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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