Merge pull request #4378 from MichaelEischer/add-version-to-snapshot
Add program version to snapshot
This commit is contained in:
commit
1b3870dc43
5 changed files with 29 additions and 0 deletions
8
changelog/unreleased/issue-4188
Normal file
8
changelog/unreleased/issue-4188
Normal file
|
@ -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
|
|
@ -645,6 +645,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts GlobalOptions, ter
|
||||||
Time: timeStamp,
|
Time: timeStamp,
|
||||||
Hostname: opts.Host,
|
Hostname: opts.Host,
|
||||||
ParentSnapshot: parentSnapshot,
|
ParentSnapshot: parentSnapshot,
|
||||||
|
ProgramVersion: "restic " + version,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !gopts.JSON {
|
if !gopts.JSON {
|
||||||
|
|
|
@ -440,6 +440,22 @@ func TestBackupTags(t *testing.T) {
|
||||||
"expected parent to be %v, got %v", parent.ID, newest.Parent)
|
"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) {
|
func TestQuietBackup(t *testing.T) {
|
||||||
env, cleanup := withTestEnvironment(t)
|
env, cleanup := withTestEnvironment(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
|
@ -680,6 +680,7 @@ type SnapshotOptions struct {
|
||||||
Excludes []string
|
Excludes []string
|
||||||
Time time.Time
|
Time time.Time
|
||||||
ParentSnapshot *restic.Snapshot
|
ParentSnapshot *restic.Snapshot
|
||||||
|
ProgramVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadParentTree loads a tree referenced by snapshot id. If id is null, nil is returned.
|
// 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
|
return nil, restic.ID{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sn.ProgramVersion = opts.ProgramVersion
|
||||||
sn.Excludes = opts.Excludes
|
sn.Excludes = opts.Excludes
|
||||||
if opts.ParentSnapshot != nil {
|
if opts.ParentSnapshot != nil {
|
||||||
sn.Parent = opts.ParentSnapshot.ID()
|
sn.Parent = opts.ParentSnapshot.ID()
|
||||||
|
|
|
@ -25,6 +25,8 @@ type Snapshot struct {
|
||||||
Tags []string `json:"tags,omitempty"`
|
Tags []string `json:"tags,omitempty"`
|
||||||
Original *ID `json:"original,omitempty"`
|
Original *ID `json:"original,omitempty"`
|
||||||
|
|
||||||
|
ProgramVersion string `json:"program_version,omitempty"`
|
||||||
|
|
||||||
id *ID // plaintext ID, used during restore
|
id *ID // plaintext ID, used during restore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue