mirror of
https://github.com/restic/restic.git
synced 2026-08-10 07:33:19 +00:00
backup - show excluded files and directories in verbose mode - text/JSON (#21887)
This commit is contained in:
@@ -129,6 +129,9 @@ type Archiver struct {
|
||||
|
||||
// Flags controlling change detection. See doc/040_backup.rst for details.
|
||||
ChangeIgnoreFlags uint
|
||||
|
||||
// for excluded items
|
||||
ExcludedItem func(path string)
|
||||
}
|
||||
|
||||
// Flags for the ChangeIgnoreFlags bitfield.
|
||||
@@ -183,6 +186,7 @@ func New(repo archiverRepo, filesystem fs.FS, opts Options) *Archiver {
|
||||
CompleteItem: func(string, ItemAction, ItemStats, time.Duration) {},
|
||||
StartFile: func(string) {},
|
||||
CompleteBlob: func(uint64) {},
|
||||
ExcludedItem: func(string) {},
|
||||
}
|
||||
|
||||
return arch
|
||||
@@ -481,6 +485,7 @@ func (arch *Archiver) save(ctx context.Context, snPath, target string, previous
|
||||
// exclude files by path before running Lstat to reduce number of lstat calls
|
||||
if !explicit && !arch.SelectByName(abstarget) {
|
||||
debug.Log("%v is excluded by path", target)
|
||||
arch.ExcludedItem(abstarget)
|
||||
return futureNode{}, true, nil
|
||||
}
|
||||
|
||||
@@ -509,6 +514,7 @@ func (arch *Archiver) save(ctx context.Context, snPath, target string, previous
|
||||
}
|
||||
if !explicit && !arch.Select(abstarget, fi, arch.FS) {
|
||||
debug.Log("%v is excluded", target)
|
||||
arch.ExcludedItem(abstarget)
|
||||
return futureNode{}, true, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -251,3 +251,18 @@ type summaryOutput struct {
|
||||
SnapshotID string `json:"snapshot_id,omitempty"`
|
||||
DryRun bool `json:"dry_run,omitempty"`
|
||||
}
|
||||
|
||||
type VerboseExclude struct {
|
||||
MessageType string `json:"message_type"` // "excluded_item"
|
||||
Item string `json:"item"` // file or directory name
|
||||
}
|
||||
|
||||
func (b *jsonProgress) ExcludedItem(path string) {
|
||||
if b.v < 2 {
|
||||
return
|
||||
}
|
||||
b.print(VerboseExclude{
|
||||
MessageType: "excluded_item",
|
||||
Item: path,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ type ProgressPrinter interface {
|
||||
ReportTotal(start time.Time, s archiver.ScanStats)
|
||||
Finish(snapshotID restic.ID, summary *archiver.Summary, dryRun bool)
|
||||
Reset()
|
||||
ExcludedItem(path string)
|
||||
|
||||
restic.Printer
|
||||
}
|
||||
@@ -162,3 +163,7 @@ func (p *Progress) Finish(snapshotID restic.ID, summary *archiver.Summary, dryru
|
||||
p.Updater.Done()
|
||||
p.printer.Finish(snapshotID, summary, dryrun)
|
||||
}
|
||||
|
||||
func (p *Progress) ExcludedItem(path string) {
|
||||
p.printer.ExcludedItem(path)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,8 @@ func (p *mockPrinter) Finish(id restic.ID, _ *archiver.Summary, _ bool) {
|
||||
p.id = id
|
||||
}
|
||||
|
||||
func (p *mockPrinter) Reset() {}
|
||||
func (p *mockPrinter) Reset() {}
|
||||
func (p *mockPrinter) ExcludedItem(_ string) {}
|
||||
|
||||
func TestProgress(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -158,3 +158,7 @@ func (b *textProgress) Finish(id restic.ID, summary *archiver.Summary, dryRun bo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (b *textProgress) ExcludedItem(path string) {
|
||||
b.VV("excluded %s", path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user