Compare commits
1 Commits
82a93c4be6
...
ede6a3ffcd
| Author | SHA1 | Date | |
|---|---|---|---|
| ede6a3ffcd |
@ -115,6 +115,30 @@ func (v *Vaultik) Restore(opts *RestoreOptions) error {
|
|||||||
}
|
}
|
||||||
defer func() { _ = blobCache.Close() }()
|
defer func() { _ = blobCache.Close() }()
|
||||||
|
|
||||||
|
// 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()
|
||||||
@ -125,10 +149,14 @@ func (v *Vaultik) Restore(opts *RestoreOptions) error {
|
|||||||
result.FilesFailed++
|
result.FilesFailed++
|
||||||
result.FailedFiles = append(result.FailedFiles, file.Path.String())
|
result.FailedFiles = append(result.FailedFiles, file.Path.String())
|
||||||
// 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)),
|
||||||
@ -137,6 +165,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