mirror of
https://github.com/octoleo/restic.git
synced 2024-10-31 19:02:32 +00:00
restic stats: add more compression statistics
Calculate and display compression ratio, space saving and progress
This commit is contained in:
parent
d66e755ac7
commit
bc945d0bf0
@ -138,9 +138,20 @@ func runStats(gopts GlobalOptions, args []string) error {
|
||||
stats.TotalSize += uint64(pbs[0].Length)
|
||||
if repo.Config().Version >= 2 {
|
||||
stats.TotalUncompressedSize += uint64(crypto.CiphertextLength(int(pbs[0].DataLength())))
|
||||
if pbs[0].IsCompressed() {
|
||||
stats.TotalCompressedBlobsSize += uint64(pbs[0].Length)
|
||||
stats.TotalCompressedBlobsUncompressedSize += uint64(crypto.CiphertextLength(int(pbs[0].DataLength())))
|
||||
}
|
||||
}
|
||||
stats.TotalBlobCount++
|
||||
}
|
||||
if stats.TotalCompressedBlobsSize > 0 {
|
||||
stats.CompressionRatio = float64(stats.TotalCompressedBlobsUncompressedSize) / float64(stats.TotalCompressedBlobsSize)
|
||||
}
|
||||
if stats.TotalUncompressedSize > 0 {
|
||||
stats.CompressionProgress = float64(stats.TotalCompressedBlobsUncompressedSize) / float64(stats.TotalUncompressedSize) * 100
|
||||
stats.CompressionSpaceSaving = (1 - float64(stats.TotalSize)/float64(stats.TotalUncompressedSize)) * 100
|
||||
}
|
||||
}
|
||||
|
||||
if gopts.JSON {
|
||||
@ -152,18 +163,26 @@ func runStats(gopts GlobalOptions, args []string) error {
|
||||
}
|
||||
|
||||
Printf("Stats in %s mode:\n", statsOptions.countMode)
|
||||
Printf(" Snapshots processed: %d\n", stats.SnapshotsCount)
|
||||
|
||||
Printf(" Snapshots processed: %d\n", stats.SnapshotsCount)
|
||||
if stats.TotalBlobCount > 0 {
|
||||
Printf(" Total Blob Count: %d\n", stats.TotalBlobCount)
|
||||
Printf(" Total Blob Count: %d\n", stats.TotalBlobCount)
|
||||
}
|
||||
if stats.TotalFileCount > 0 {
|
||||
Printf(" Total File Count: %d\n", stats.TotalFileCount)
|
||||
Printf(" Total File Count: %d\n", stats.TotalFileCount)
|
||||
}
|
||||
if stats.TotalUncompressedSize > 0 {
|
||||
Printf("Total Uncompressed Size: %-5s\n", formatBytes(stats.TotalUncompressedSize))
|
||||
Printf(" Total Uncompressed Size: %-5s\n", formatBytes(stats.TotalUncompressedSize))
|
||||
}
|
||||
Printf(" Total Size: %-5s\n", formatBytes(stats.TotalSize))
|
||||
if stats.CompressionProgress > 0 {
|
||||
Printf(" Compression Progress: %.2f%%\n", stats.CompressionProgress)
|
||||
}
|
||||
if stats.CompressionRatio > 0 {
|
||||
Printf(" Compression Ratio: %.2fx\n", stats.CompressionRatio)
|
||||
}
|
||||
if stats.CompressionSpaceSaving > 0 {
|
||||
Printf("Compression Space Saving: %.2f%%\n", stats.CompressionSpaceSaving)
|
||||
}
|
||||
Printf(" Total Size: %-5s\n", formatBytes(stats.TotalSize))
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -289,10 +308,15 @@ func verifyStatsInput(gopts GlobalOptions, args []string) error {
|
||||
// to collect information about it, as well as state needed
|
||||
// for a successful and efficient walk.
|
||||
type statsContainer struct {
|
||||
TotalSize uint64 `json:"total_size"`
|
||||
TotalUncompressedSize uint64 `json:"total_uncompressed_size,omitempty"`
|
||||
TotalFileCount uint64 `json:"total_file_count"`
|
||||
TotalBlobCount uint64 `json:"total_blob_count,omitempty"`
|
||||
TotalSize uint64 `json:"total_size"`
|
||||
TotalUncompressedSize uint64 `json:"total_uncompressed_size,omitempty"`
|
||||
TotalCompressedBlobsSize uint64 `json:"-"`
|
||||
TotalCompressedBlobsUncompressedSize uint64 `json:"-"`
|
||||
CompressionRatio float64 `json:"compression_ratio,omitempty"`
|
||||
CompressionProgress float64 `json:"compression_progress,omitempty"`
|
||||
CompressionSpaceSaving float64 `json:"compression_space_saving,omitempty"`
|
||||
TotalFileCount uint64 `json:"total_file_count,omitempty"`
|
||||
TotalBlobCount uint64 `json:"total_blob_count,omitempty"`
|
||||
// holds count of all considered snapshots
|
||||
SnapshotsCount int `json:"snapshots_count"`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user