mirror of
https://github.com/restic/restic.git
synced 2025-03-30 00:00:14 +01:00
prune: Unify statistics computation
+ prepare JSON output
This commit is contained in:
parent
da47967316
commit
ae0835f12d
2 changed files with 53 additions and 36 deletions
|
@ -232,24 +232,19 @@ func printPruneStats(printer progress.Printer, stats repository.PruneStats) erro
|
|||
if stats.Size.Unref > 0 {
|
||||
printer.V("unreferenced: %s\n", ui.FormatBytes(stats.Size.Unref))
|
||||
}
|
||||
totalBlobs := stats.Blobs.Used + stats.Blobs.Unused + stats.Blobs.Duplicate
|
||||
totalSize := stats.Size.Used + stats.Size.Duplicate + stats.Size.Unused + stats.Size.Unref
|
||||
unusedSize := stats.Size.Duplicate + stats.Size.Unused
|
||||
printer.V("total: %10d blobs / %s\n", totalBlobs, ui.FormatBytes(totalSize))
|
||||
printer.V("unused size: %s of total size\n", ui.FormatPercent(unusedSize, totalSize))
|
||||
printer.V("total: %10d blobs / %s\n", stats.Blobs.Total, ui.FormatBytes(stats.Size.Total))
|
||||
printer.V("unused size: %s of total size\n", ui.FormatPercent(stats.Size.Unused, stats.Size.Total))
|
||||
|
||||
printer.P("\nto repack: %10d blobs / %s\n", stats.Blobs.Repack, ui.FormatBytes(stats.Size.Repack))
|
||||
printer.P("this removes: %10d blobs / %s\n", stats.Blobs.Repackrm, ui.FormatBytes(stats.Size.Repackrm))
|
||||
printer.P("to delete: %10d blobs / %s\n", stats.Blobs.Remove, ui.FormatBytes(stats.Size.Remove+stats.Size.Unref))
|
||||
totalPruneSize := stats.Size.Remove + stats.Size.Repackrm + stats.Size.Unref
|
||||
printer.P("total prune: %10d blobs / %s\n", stats.Blobs.Remove+stats.Blobs.Repackrm, ui.FormatBytes(totalPruneSize))
|
||||
if stats.Size.Uncompressed > 0 {
|
||||
printer.P("not yet compressed: %s\n", ui.FormatBytes(stats.Size.Uncompressed))
|
||||
printer.P("total prune: %10d blobs / %s\n", stats.Blobs.RemoveTotal, ui.FormatBytes(stats.Size.RemoveTotal))
|
||||
if stats.Size.Uncompressed > 0 {
|
||||
printer.P("not yet compressed: %s\n", ui.FormatBytes(stats.Size.Uncompressed))
|
||||
}
|
||||
printer.P("remaining: %10d blobs / %s\n", totalBlobs-(stats.Blobs.Remove+stats.Blobs.Repackrm), ui.FormatBytes(totalSize-totalPruneSize))
|
||||
unusedAfter := unusedSize - stats.Size.Remove - stats.Size.Repackrm
|
||||
printer.P("remaining: %10d blobs / %s\n", stats.Blobs.Remain, ui.FormatBytes(stats.Size.Remain))
|
||||
printer.P("unused size after prune: %s (%s of remaining size)\n",
|
||||
ui.FormatBytes(unusedAfter), ui.FormatPercent(unusedAfter, totalSize-totalPruneSize))
|
||||
ui.FormatBytes(stats.Size.RemainUnused), ui.FormatPercent(stats.Size.RemainUnused, stats.Size.Remain))
|
||||
printer.P("\n")
|
||||
printer.V("totally used packs: %10d\n", stats.Packs.Used)
|
||||
printer.V("partly used packs: %10d\n", stats.Packs.PartlyUsed)
|
||||
|
|
|
@ -32,32 +32,42 @@ type PruneOptions struct {
|
|||
|
||||
type PruneStats struct {
|
||||
Blobs struct {
|
||||
Used uint
|
||||
Duplicate uint
|
||||
Unused uint
|
||||
Remove uint
|
||||
Repack uint
|
||||
Repackrm uint
|
||||
}
|
||||
Used uint `json:"used"`
|
||||
Duplicate uint `json:"duplicate"`
|
||||
Unused uint `json:"unused"`
|
||||
Total uint `json:"total"`
|
||||
Repack uint `json:"repack"`
|
||||
Repackrm uint `json:"repack_remove"`
|
||||
Remove uint `json:"remove"`
|
||||
RemoveTotal uint `json:"remove_total"`
|
||||
Remain uint `json:"remaining"`
|
||||
RemainUnused uint `json:"remaining_unused"`
|
||||
} `json:"blobs"`
|
||||
Size struct {
|
||||
Used uint64
|
||||
Duplicate uint64
|
||||
Unused uint64
|
||||
Remove uint64
|
||||
Repack uint64
|
||||
Repackrm uint64
|
||||
Unref uint64
|
||||
Uncompressed uint64
|
||||
}
|
||||
Used uint64 `json:"used"`
|
||||
Duplicate uint64 `json:"duplicate"`
|
||||
Unused uint64 `json:"unused"`
|
||||
Unref uint64 `json:"unreferenced"`
|
||||
Uncompressed uint64 `json:"uncompressed"`
|
||||
Total uint64 `json:"total"`
|
||||
Repack uint64 `json:"repack"`
|
||||
Repackrm uint64 `json:"repack_remove"`
|
||||
Remove uint64 `json:"remove"`
|
||||
RemoveTotal uint64 `json:"remove_total"`
|
||||
Remain uint64 `json:"remaining"`
|
||||
RemainUnused uint64 `json:"remaining_unused"`
|
||||
} `json:"bytes"`
|
||||
Packs struct {
|
||||
Used uint
|
||||
Unused uint
|
||||
PartlyUsed uint
|
||||
Unref uint
|
||||
Keep uint
|
||||
Repack uint
|
||||
Remove uint
|
||||
}
|
||||
Used uint `json:"used"`
|
||||
Unused uint `json:"unused"`
|
||||
PartlyUsed uint `json:"partly_used"`
|
||||
Unref uint `json:"unreferenced"`
|
||||
Total uint `json:"total"`
|
||||
Keep uint `json:"keep"`
|
||||
Repack uint `json:"repack"`
|
||||
Remove uint `json:"remove"`
|
||||
RemoveTotal uint `json:"remove_total"`
|
||||
} `json:"packfiles"`
|
||||
}
|
||||
|
||||
type PrunePlan struct {
|
||||
|
@ -141,6 +151,18 @@ func PlanPrune(ctx context.Context, opts PruneOptions, repo *Repository, getUsed
|
|||
}
|
||||
plan.keepBlobs = keepBlobs
|
||||
|
||||
// calculate totals for statistics
|
||||
stats.Blobs.Total = stats.Blobs.Used + stats.Blobs.Unused + stats.Blobs.Duplicate
|
||||
stats.Blobs.RemoveTotal = stats.Blobs.Remove + stats.Blobs.Repackrm
|
||||
stats.Blobs.Remain = stats.Blobs.Total - stats.Blobs.RemoveTotal
|
||||
stats.Size.Total = stats.Size.Used + stats.Size.Duplicate + stats.Size.Unused + stats.Size.Unref
|
||||
stats.Size.Unused = stats.Size.Duplicate + stats.Size.Unused
|
||||
stats.Size.RemoveTotal = stats.Size.Remove + stats.Size.Repackrm + stats.Size.Unref
|
||||
stats.Size.Remain = stats.Size.Total - stats.Size.RemoveTotal
|
||||
stats.Size.RemainUnused = stats.Size.Unused - stats.Size.Remove - stats.Size.Repackrm
|
||||
stats.Packs.Total = stats.Packs.Used + stats.Packs.PartlyUsed + stats.Packs.Unused + stats.Packs.Unref
|
||||
stats.Packs.RemoveTotal = stats.Packs.Unref + stats.Packs.Remove
|
||||
|
||||
plan.repo = repo
|
||||
plan.stats = stats
|
||||
plan.opts = opts
|
||||
|
|
Loading…
Add table
Reference in a new issue