forked from TrueCloudLab/restic
backup: store statistics in snapshot
This commit is contained in:
parent
86897314d5
commit
38f91d3b5e
3 changed files with 41 additions and 1 deletions
|
@ -451,6 +451,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||||
}
|
}
|
||||||
|
|
||||||
timeStamp := time.Now()
|
timeStamp := time.Now()
|
||||||
|
backupStart := timeStamp
|
||||||
if opts.TimeStamp != "" {
|
if opts.TimeStamp != "" {
|
||||||
timeStamp, err = time.ParseInLocation(TimeFormat, opts.TimeStamp, time.Local)
|
timeStamp, err = time.ParseInLocation(TimeFormat, opts.TimeStamp, time.Local)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -640,6 +641,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||||
snapshotOpts := archiver.SnapshotOptions{
|
snapshotOpts := archiver.SnapshotOptions{
|
||||||
Excludes: opts.Excludes,
|
Excludes: opts.Excludes,
|
||||||
Tags: opts.Tags.Flatten(),
|
Tags: opts.Tags.Flatten(),
|
||||||
|
BackupStart: backupStart,
|
||||||
Time: timeStamp,
|
Time: timeStamp,
|
||||||
Hostname: opts.Host,
|
Hostname: opts.Host,
|
||||||
ParentSnapshot: parentSnapshot,
|
ParentSnapshot: parentSnapshot,
|
||||||
|
|
|
@ -739,6 +739,7 @@ type SnapshotOptions struct {
|
||||||
Tags restic.TagList
|
Tags restic.TagList
|
||||||
Hostname string
|
Hostname string
|
||||||
Excludes []string
|
Excludes []string
|
||||||
|
BackupStart time.Time
|
||||||
Time time.Time
|
Time time.Time
|
||||||
ParentSnapshot *restic.Snapshot
|
ParentSnapshot *restic.Snapshot
|
||||||
ProgramVersion string
|
ProgramVersion string
|
||||||
|
@ -866,6 +867,23 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps
|
||||||
sn.Parent = opts.ParentSnapshot.ID()
|
sn.Parent = opts.ParentSnapshot.ID()
|
||||||
}
|
}
|
||||||
sn.Tree = &rootTreeID
|
sn.Tree = &rootTreeID
|
||||||
|
sn.Summary = &restic.SnapshotSummary{
|
||||||
|
BackupStart: opts.BackupStart,
|
||||||
|
BackupEnd: time.Now(),
|
||||||
|
|
||||||
|
FilesNew: arch.summary.Files.New,
|
||||||
|
FilesChanged: arch.summary.Files.Changed,
|
||||||
|
FilesUnmodified: arch.summary.Files.Unchanged,
|
||||||
|
DirsNew: arch.summary.Dirs.New,
|
||||||
|
DirsChanged: arch.summary.Dirs.Changed,
|
||||||
|
DirsUnmodified: arch.summary.Dirs.Unchanged,
|
||||||
|
DataBlobs: arch.summary.ItemStats.DataBlobs,
|
||||||
|
TreeBlobs: arch.summary.ItemStats.TreeBlobs,
|
||||||
|
DataAdded: arch.summary.ItemStats.DataSize + arch.summary.ItemStats.TreeSize,
|
||||||
|
DataAddedInRepo: arch.summary.ItemStats.DataSizeInRepo + arch.summary.ItemStats.TreeSizeInRepo,
|
||||||
|
TotalFilesProcessed: arch.summary.Files.New + arch.summary.Files.Changed + arch.summary.Files.Unchanged,
|
||||||
|
TotalBytesProcessed: arch.summary.ProcessedBytes,
|
||||||
|
}
|
||||||
|
|
||||||
id, err := restic.SaveSnapshot(ctx, arch.Repo, sn)
|
id, err := restic.SaveSnapshot(ctx, arch.Repo, sn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -26,10 +26,30 @@ type Snapshot struct {
|
||||||
Original *ID `json:"original,omitempty"`
|
Original *ID `json:"original,omitempty"`
|
||||||
|
|
||||||
ProgramVersion string `json:"program_version,omitempty"`
|
ProgramVersion string `json:"program_version,omitempty"`
|
||||||
|
Summary *SnapshotSummary `json:"summary,omitempty"`
|
||||||
|
|
||||||
id *ID // plaintext ID, used during restore
|
id *ID // plaintext ID, used during restore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SnapshotSummary struct {
|
||||||
|
BackupStart time.Time `json:"backup_start"`
|
||||||
|
BackupEnd time.Time `json:"backup_end"`
|
||||||
|
|
||||||
|
// statistics from the backup json output
|
||||||
|
FilesNew uint `json:"files_new"`
|
||||||
|
FilesChanged uint `json:"files_changed"`
|
||||||
|
FilesUnmodified uint `json:"files_unmodified"`
|
||||||
|
DirsNew uint `json:"dirs_new"`
|
||||||
|
DirsChanged uint `json:"dirs_changed"`
|
||||||
|
DirsUnmodified uint `json:"dirs_unmodified"`
|
||||||
|
DataBlobs int `json:"data_blobs"`
|
||||||
|
TreeBlobs int `json:"tree_blobs"`
|
||||||
|
DataAdded uint64 `json:"data_added"`
|
||||||
|
DataAddedInRepo uint64 `json:"data_added_in_repo"`
|
||||||
|
TotalFilesProcessed uint `json:"total_files_processed"`
|
||||||
|
TotalBytesProcessed uint64 `json:"total_bytes_processed"`
|
||||||
|
}
|
||||||
|
|
||||||
// NewSnapshot returns an initialized snapshot struct for the current user and
|
// NewSnapshot returns an initialized snapshot struct for the current user and
|
||||||
// time.
|
// time.
|
||||||
func NewSnapshot(paths []string, tags []string, hostname string, time time.Time) (*Snapshot, error) {
|
func NewSnapshot(paths []string, tags []string, hostname string, time time.Time) (*Snapshot, error) {
|
||||||
|
|
Loading…
Reference in a new issue