Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add program version to snapshot #4378

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/issue-4188
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Enhancement: `backup` includes restic version in snapshot metadata

The restic version used backup the snapshot is now included in its metadata.
The program version is shown when inspecting a snapshot using `restic cat
snapshot <snapshotID>` or `restic snapshots --json`.

https://github.com/restic/restic/issues/4188
https://github.com/restic/restic/pull/4378
1 change: 1 addition & 0 deletions cmd/restic/cmd_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
Time: timeStamp,
Hostname: opts.Host,
ParentSnapshot: parentSnapshot,
ProgramVersion: "restic " + version,
}

if !gopts.JSON {
Expand Down
16 changes: 16 additions & 0 deletions cmd/restic/cmd_backup_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,22 @@ func TestBackupTags(t *testing.T) {
"expected parent to be %v, got %v", parent.ID, newest.Parent)
}

func TestBackupProgramVersion(t *testing.T) {
env, cleanup := withTestEnvironment(t)
defer cleanup()

testSetupBackupData(t, env)
testRunBackup(t, "", []string{env.testdata}, BackupOptions{}, env.gopts)
newest, _ := testRunSnapshots(t, env.gopts)

if newest == nil {
t.Fatal("expected a backup, got nil")
}
resticVersion := "restic " + version
rtest.Assert(t, newest.ProgramVersion == resticVersion,
"expected %v, got %v", resticVersion, newest.ProgramVersion)
}

func TestQuietBackup(t *testing.T) {
env, cleanup := withTestEnvironment(t)
defer cleanup()
Expand Down
2 changes: 2 additions & 0 deletions internal/archiver/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ type SnapshotOptions struct {
Excludes []string
Time time.Time
ParentSnapshot *restic.Snapshot
ProgramVersion string
}

// loadParentTree loads a tree referenced by snapshot id. If id is null, nil is returned.
Expand Down Expand Up @@ -796,6 +797,7 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps
return nil, restic.ID{}, err
}

sn.ProgramVersion = opts.ProgramVersion
sn.Excludes = opts.Excludes
if opts.ParentSnapshot != nil {
sn.Parent = opts.ParentSnapshot.ID()
Expand Down
2 changes: 2 additions & 0 deletions internal/restic/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Snapshot struct {
Tags []string `json:"tags,omitempty"`
Original *ID `json:"original,omitempty"`

ProgramVersion string `json:"program_version,omitempty"`

id *ID // plaintext ID, used during restore
}

Expand Down