mirror of
https://github.com/restic/restic.git
synced 2025-03-15 10:20:59 +00:00
Merge pull request #4737 from stephan0307/3117
json output forget command: added id's in snapshots within reasons object
This commit is contained in:
commit
831fc4413d
5
changelog/unreleased/pull-4737
Normal file
5
changelog/unreleased/pull-4737
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Enhancement: include snapshot id in reason field of forget JSON output
|
||||||
|
|
||||||
|
The JSON output of the `forget` command now includes the `id` and `short_id` of a snapshot in the `reason` field.
|
||||||
|
|
||||||
|
https://github.com/restic/restic/pull/4737
|
@ -245,16 +245,16 @@ func runForget(ctx context.Context, opts ForgetOptions, pruneOptions PruneOption
|
|||||||
PrintSnapshots(globalOptions.stdout, keep, reasons, opts.Compact)
|
PrintSnapshots(globalOptions.stdout, keep, reasons, opts.Compact)
|
||||||
Printf("\n")
|
Printf("\n")
|
||||||
}
|
}
|
||||||
addJSONSnapshots(&fg.Keep, keep)
|
fg.Keep = asJSONSnapshots(keep)
|
||||||
|
|
||||||
if len(remove) != 0 && !gopts.Quiet && !gopts.JSON {
|
if len(remove) != 0 && !gopts.Quiet && !gopts.JSON {
|
||||||
Printf("remove %d snapshots:\n", len(remove))
|
Printf("remove %d snapshots:\n", len(remove))
|
||||||
PrintSnapshots(globalOptions.stdout, remove, nil, opts.Compact)
|
PrintSnapshots(globalOptions.stdout, remove, nil, opts.Compact)
|
||||||
Printf("\n")
|
Printf("\n")
|
||||||
}
|
}
|
||||||
addJSONSnapshots(&fg.Remove, remove)
|
fg.Remove = asJSONSnapshots(remove)
|
||||||
|
|
||||||
fg.Reasons = reasons
|
fg.Reasons = asJSONKeeps(reasons)
|
||||||
|
|
||||||
jsonGroups = append(jsonGroups, &fg)
|
jsonGroups = append(jsonGroups, &fg)
|
||||||
|
|
||||||
@ -307,18 +307,42 @@ type ForgetGroup struct {
|
|||||||
Paths []string `json:"paths"`
|
Paths []string `json:"paths"`
|
||||||
Keep []Snapshot `json:"keep"`
|
Keep []Snapshot `json:"keep"`
|
||||||
Remove []Snapshot `json:"remove"`
|
Remove []Snapshot `json:"remove"`
|
||||||
Reasons []restic.KeepReason `json:"reasons"`
|
Reasons []KeepReason `json:"reasons"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func addJSONSnapshots(js *[]Snapshot, list restic.Snapshots) {
|
func asJSONSnapshots(list restic.Snapshots) []Snapshot {
|
||||||
|
var resultList []Snapshot
|
||||||
for _, sn := range list {
|
for _, sn := range list {
|
||||||
k := Snapshot{
|
k := Snapshot{
|
||||||
Snapshot: sn,
|
Snapshot: sn,
|
||||||
ID: sn.ID(),
|
ID: sn.ID(),
|
||||||
ShortID: sn.ID().Str(),
|
ShortID: sn.ID().Str(),
|
||||||
}
|
}
|
||||||
*js = append(*js, k)
|
resultList = append(resultList, k)
|
||||||
}
|
}
|
||||||
|
return resultList
|
||||||
|
}
|
||||||
|
|
||||||
|
// KeepReason helps to print KeepReasons as JSON with Snapshots with their ID included.
|
||||||
|
type KeepReason struct {
|
||||||
|
Snapshot Snapshot `json:"snapshot"`
|
||||||
|
Matches []string `json:"matches"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func asJSONKeeps(list []restic.KeepReason) []KeepReason {
|
||||||
|
var resultList []KeepReason
|
||||||
|
for _, keep := range list {
|
||||||
|
k := KeepReason{
|
||||||
|
Snapshot: Snapshot{
|
||||||
|
Snapshot: keep.Snapshot,
|
||||||
|
ID: keep.Snapshot.ID(),
|
||||||
|
ShortID: keep.Snapshot.ID().Str(),
|
||||||
|
},
|
||||||
|
Matches: keep.Matches,
|
||||||
|
}
|
||||||
|
resultList = append(resultList, k)
|
||||||
|
}
|
||||||
|
return resultList
|
||||||
}
|
}
|
||||||
|
|
||||||
func printJSONForget(stdout io.Writer, forgets []*ForgetGroup) error {
|
func printJSONForget(stdout io.Writer, forgets []*ForgetGroup) error {
|
||||||
|
@ -367,13 +367,13 @@ Snapshot object
|
|||||||
|
|
||||||
Reason object
|
Reason object
|
||||||
|
|
||||||
+----------------+---------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
| ``snapshot`` | Snapshot object, without ``id`` and ``short_id`` fields |
|
| ``snapshot`` | Snapshot object, including ``id`` and ``short_id`` fields |
|
||||||
+----------------+---------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
| ``matches`` | Array containing descriptions of the matching criteria |
|
| ``matches`` | Array containing descriptions of the matching criteria |
|
||||||
+----------------+---------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
| ``counters`` | Object containing counters used by the policies |
|
| ``counters`` | Object containing counters used by the policies |
|
||||||
+----------------+---------------------------------------------------------+
|
+----------------+-----------------------------------------------------------+
|
||||||
|
|
||||||
|
|
||||||
init
|
init
|
||||||
|
Loading…
x
Reference in New Issue
Block a user