mirror of
https://github.com/octoleo/restic.git
synced 2024-11-30 00:33:57 +00:00
ui: move SetDryRun to ProgressReporter
This commit is contained in:
parent
77b129ec74
commit
d62bfed65d
@ -537,7 +537,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina
|
|||||||
|
|
||||||
if opts.DryRun {
|
if opts.DryRun {
|
||||||
repo.SetDryRun()
|
repo.SetDryRun()
|
||||||
progressPrinter.SetDryRun()
|
progressReporter.SetDryRun()
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the terminal for stdout/stderr
|
// use the terminal for stdout/stderr
|
||||||
|
@ -17,7 +17,6 @@ type Backup struct {
|
|||||||
*StdioWrapper
|
*StdioWrapper
|
||||||
|
|
||||||
term *termstatus.Terminal
|
term *termstatus.Terminal
|
||||||
dry bool // true if writes are faked
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBackup returns a new backup progress reporter.
|
// NewBackup returns a new backup progress reporter.
|
||||||
@ -165,14 +164,14 @@ func (b *Backup) Reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finish prints the finishing messages.
|
// Finish prints the finishing messages.
|
||||||
func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *Summary) {
|
func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *Summary, dryRun bool) {
|
||||||
b.P("\n")
|
b.P("\n")
|
||||||
b.P("Files: %5d new, %5d changed, %5d unmodified\n", summary.Files.New, summary.Files.Changed, summary.Files.Unchanged)
|
b.P("Files: %5d new, %5d changed, %5d unmodified\n", summary.Files.New, summary.Files.Changed, summary.Files.Unchanged)
|
||||||
b.P("Dirs: %5d new, %5d changed, %5d unmodified\n", summary.Dirs.New, summary.Dirs.Changed, summary.Dirs.Unchanged)
|
b.P("Dirs: %5d new, %5d changed, %5d unmodified\n", summary.Dirs.New, summary.Dirs.Changed, summary.Dirs.Unchanged)
|
||||||
b.V("Data Blobs: %5d new\n", summary.ItemStats.DataBlobs)
|
b.V("Data Blobs: %5d new\n", summary.ItemStats.DataBlobs)
|
||||||
b.V("Tree Blobs: %5d new\n", summary.ItemStats.TreeBlobs)
|
b.V("Tree Blobs: %5d new\n", summary.ItemStats.TreeBlobs)
|
||||||
verb := "Added"
|
verb := "Added"
|
||||||
if b.dry {
|
if dryRun {
|
||||||
verb = "Would add"
|
verb = "Would add"
|
||||||
}
|
}
|
||||||
b.P("%s to the repo: %-5s\n", verb, formatBytes(summary.ItemStats.DataSize+summary.ItemStats.TreeSize))
|
b.P("%s to the repo: %-5s\n", verb, formatBytes(summary.ItemStats.DataSize+summary.ItemStats.TreeSize))
|
||||||
@ -183,7 +182,3 @@ func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *Summary)
|
|||||||
formatDuration(time.Since(start)),
|
formatDuration(time.Since(start)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backup) SetDryRun() {
|
|
||||||
b.dry = true
|
|
||||||
}
|
|
||||||
|
@ -20,7 +20,6 @@ type Backup struct {
|
|||||||
|
|
||||||
term *termstatus.Terminal
|
term *termstatus.Terminal
|
||||||
v uint
|
v uint
|
||||||
dry bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBackup returns a new backup progress reporter.
|
// NewBackup returns a new backup progress reporter.
|
||||||
@ -169,7 +168,7 @@ func (b *Backup) ReportTotal(item string, start time.Time, s archiver.ScanStats)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finish prints the finishing messages.
|
// Finish prints the finishing messages.
|
||||||
func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *ui.Summary) {
|
func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *ui.Summary, dryRun bool) {
|
||||||
b.print(summaryOutput{
|
b.print(summaryOutput{
|
||||||
MessageType: "summary",
|
MessageType: "summary",
|
||||||
FilesNew: summary.Files.New,
|
FilesNew: summary.Files.New,
|
||||||
@ -185,7 +184,7 @@ func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *ui.Summa
|
|||||||
TotalBytesProcessed: summary.ProcessedBytes,
|
TotalBytesProcessed: summary.ProcessedBytes,
|
||||||
TotalDuration: time.Since(start).Seconds(),
|
TotalDuration: time.Since(start).Seconds(),
|
||||||
SnapshotID: snapshotID.Str(),
|
SnapshotID: snapshotID.Str(),
|
||||||
DryRun: b.dry,
|
DryRun: dryRun,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,11 +192,6 @@ func (b *Backup) Finish(snapshotID restic.ID, start time.Time, summary *ui.Summa
|
|||||||
func (b *Backup) Reset() {
|
func (b *Backup) Reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDryRun marks the backup as a "dry run".
|
|
||||||
func (b *Backup) SetDryRun() {
|
|
||||||
b.dry = true
|
|
||||||
}
|
|
||||||
|
|
||||||
type statusUpdate struct {
|
type statusUpdate struct {
|
||||||
MessageType string `json:"message_type"` // "status"
|
MessageType string `json:"message_type"` // "status"
|
||||||
SecondsElapsed uint64 `json:"seconds_elapsed,omitempty"`
|
SecondsElapsed uint64 `json:"seconds_elapsed,omitempty"`
|
||||||
|
@ -18,9 +18,8 @@ type ProgressPrinter interface {
|
|||||||
ScannerError(item string, fi os.FileInfo, err error) error
|
ScannerError(item string, fi os.FileInfo, err error) error
|
||||||
CompleteItem(messageType string, item string, previous, current *restic.Node, s archiver.ItemStats, d time.Duration)
|
CompleteItem(messageType string, item string, previous, current *restic.Node, s archiver.ItemStats, d time.Duration)
|
||||||
ReportTotal(item string, start time.Time, s archiver.ScanStats)
|
ReportTotal(item string, start time.Time, s archiver.ScanStats)
|
||||||
Finish(snapshotID restic.ID, start time.Time, summary *Summary)
|
Finish(snapshotID restic.ID, start time.Time, summary *Summary, dryRun bool)
|
||||||
Reset()
|
Reset()
|
||||||
SetDryRun()
|
|
||||||
|
|
||||||
// ui.StdioWrapper
|
// ui.StdioWrapper
|
||||||
Stdout() io.WriteCloser
|
Stdout() io.WriteCloser
|
||||||
@ -69,6 +68,7 @@ type Progress struct {
|
|||||||
MinUpdatePause time.Duration
|
MinUpdatePause time.Duration
|
||||||
|
|
||||||
start time.Time
|
start time.Time
|
||||||
|
dry bool
|
||||||
|
|
||||||
totalBytes uint64
|
totalBytes uint64
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ func (p *Progress) ReportTotal(item string, s archiver.ScanStats) {
|
|||||||
func (p *Progress) Finish(snapshotID restic.ID) {
|
func (p *Progress) Finish(snapshotID restic.ID) {
|
||||||
// wait for the status update goroutine to shut down
|
// wait for the status update goroutine to shut down
|
||||||
<-p.closed
|
<-p.closed
|
||||||
p.printer.Finish(snapshotID, p.start, p.summary)
|
p.printer.Finish(snapshotID, p.start, p.summary, p.dry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetMinUpdatePause sets b.MinUpdatePause. It satisfies the
|
// SetMinUpdatePause sets b.MinUpdatePause. It satisfies the
|
||||||
@ -318,3 +318,8 @@ func (p *Progress) Finish(snapshotID restic.ID) {
|
|||||||
func (p *Progress) SetMinUpdatePause(d time.Duration) {
|
func (p *Progress) SetMinUpdatePause(d time.Duration) {
|
||||||
p.MinUpdatePause = d
|
p.MinUpdatePause = d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetDryRun marks the backup as a "dry run".
|
||||||
|
func (p *Progress) SetDryRun() {
|
||||||
|
p.dry = true
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user