Files
kopia/snapshot/stats.go
Jarek Kowalski 23273af1cd snapshot: reworked error handling and added fail-fast option (#840)
Fixes #690

This is a breaking change for folks who are expecting snapshots to fail
quickly without writing a snapshot manifest in case of an error.

Before this change, any source read failure would cause the entire
snapshot to fail (and not write a snapshot manifest as a result),
unless `ignoreFileErrors` or `ignoreDirectoryErrors` was set.

The new behavior is to continue snapshotting remaining files and
directories (this can be disabled by passing `--fail-fast` flag or
setting `KOPIA_SNAPSHOT_FAIL_FAST=1` environment variable) and defer
returning an error until the very end.

After snapshotting we will always attempt to write the snapshot manifest
(except when the root of the snapshot itself cannot be opened). In case
of a fail-fast error, the manifest will be marked as 'partial' and
the directory tree will contain only partial set of files.

In case of any errors, the manifest (and each directory object) will
list the number if failures and no more than 10 examples of failed
files/directories along with their respective errors.

Once the snapshot is complete we will return non-zero exit code to the
operating system if there were any fatal errors during snapshotting.

With this change we are repurposing `ignoreFileErrors` and
`ignoreDirectoryErrors` to designate some errors as non-fatal.
Non-fatal errors are reported as warnings in the logs and will not
cause a non-zero exit code to be returned.
2021-02-17 10:29:01 -08:00

38 lines
1.0 KiB
Go

package snapshot
import (
"sync/atomic"
"github.com/kopia/kopia/fs"
)
// Stats keeps track of snapshot generation statistics.
type Stats struct {
// keep all int64 aligned because they will be atomically updated
TotalFileSize int64 `json:"totalSize"`
ExcludedTotalFileSize int64 `json:"excludedTotalSize"`
// keep all int32 aligned because they will be atomically updated
TotalFileCount int32 `json:"fileCount"`
CachedFiles int32 `json:"cachedFiles"`
NonCachedFiles int32 `json:"nonCachedFiles"`
TotalDirectoryCount int32 `json:"dirCount"`
ExcludedFileCount int32 `json:"excludedFileCount"`
ExcludedDirCount int32 `json:"excludedDirCount"`
IgnoredErrorCount int32 `json:"ignoredErrorCount"`
ErrorCount int32 `json:"errorCount"`
}
// AddExcluded adds the information about excluded file to the statistics.
func (s *Stats) AddExcluded(md fs.Entry) {
if md.IsDir() {
atomic.AddInt32(&s.ExcludedDirCount, 1)
} else {
atomic.AddInt32(&s.ExcludedFileCount, 1)
atomic.AddInt64(&s.ExcludedTotalFileSize, md.Size())
}
}