From bbac74b17225642380a52da1d96ace6c401285d7 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 19 Jun 2023 19:30:41 +0200 Subject: [PATCH 1/3] add program version to snapshot --- changelog/unreleased/issue-4188 | 7 +++++++ cmd/restic/cmd_backup.go | 1 + internal/archiver/archiver.go | 2 ++ internal/restic/snapshot.go | 2 ++ 4 files changed, 12 insertions(+) create mode 100644 changelog/unreleased/issue-4188 diff --git a/changelog/unreleased/issue-4188 b/changelog/unreleased/issue-4188 new file mode 100644 index 000000000..377468a76 --- /dev/null +++ b/changelog/unreleased/issue-4188 @@ -0,0 +1,7 @@ +Enhancement: Include client version in snapshot metadata + +The client version number is now included in the `program_version` field of a snapshot. +It can be inspected by using either `restic cat snapshot snapshotID` or `restic snapshots --json`. + +https://github.com/restic/restic/issues/4188 +https://github.com/restic/restic/pull/4378 diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index f12f70e39..d7e899eaf 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -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 { diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go index 3c1cc33d0..98819d797 100644 --- a/internal/archiver/archiver.go +++ b/internal/archiver/archiver.go @@ -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. @@ -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() diff --git a/internal/restic/snapshot.go b/internal/restic/snapshot.go index 1f6e4534b..13e795ec8 100644 --- a/internal/restic/snapshot.go +++ b/internal/restic/snapshot.go @@ -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 } From 389f6ee74c717e28b99b9418021bb43f0cc972eb Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 7 Jul 2023 23:33:23 +0200 Subject: [PATCH 2/3] backup: add minimal test for program versioni --- cmd/restic/cmd_backup_integration_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/restic/cmd_backup_integration_test.go b/cmd/restic/cmd_backup_integration_test.go index b81db21e6..fb7bef633 100644 --- a/cmd/restic/cmd_backup_integration_test.go +++ b/cmd/restic/cmd_backup_integration_test.go @@ -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() From e703e89e9bb72abd9d1e9f90466c891229d3c0fd Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Fri, 7 Jul 2023 23:36:57 +0200 Subject: [PATCH 3/3] add changelog for program version --- changelog/unreleased/issue-4188 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/changelog/unreleased/issue-4188 b/changelog/unreleased/issue-4188 index 377468a76..dbb26f733 100644 --- a/changelog/unreleased/issue-4188 +++ b/changelog/unreleased/issue-4188 @@ -1,7 +1,8 @@ -Enhancement: Include client version in snapshot metadata +Enhancement: `backup` includes restic version in snapshot metadata -The client version number is now included in the `program_version` field of a snapshot. -It can be inspected by using either `restic cat snapshot snapshotID` or `restic snapshots --json`. +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 ` or `restic snapshots --json`. https://github.com/restic/restic/issues/4188 https://github.com/restic/restic/pull/4378