From 32f5ee6f4eac0b6cfd8f96485bbef986c873d99b Mon Sep 17 00:00:00 2001 From: arjunajesh <34989598+arjunajesh@users.noreply.github.com> Date: Sun, 16 Jul 2023 13:51:24 -0400 Subject: [PATCH] snapshots sorted by timestamp --- changelog/unreleased/issue-1495 | 7 +++++++ cmd/restic/cmd_find.go | 9 +++++++++ 2 files changed, 16 insertions(+) create mode 100644 changelog/unreleased/issue-1495 diff --git a/changelog/unreleased/issue-1495 b/changelog/unreleased/issue-1495 new file mode 100644 index 000000000..5aa682efa --- /dev/null +++ b/changelog/unreleased/issue-1495 @@ -0,0 +1,7 @@ +Enhancement: Snapshots are sorted by timestamp in the output of `restic find` + +The `find` command printed snapshots in an arbitrary order. Now restic prints +the snapshots sorted by timestamp. + +https://github.com/restic/restic/issues/1495 +https://github.com/restic/restic/pull/4409 diff --git a/cmd/restic/cmd_find.go b/cmd/restic/cmd_find.go index e1161797b..181d8595d 100644 --- a/cmd/restic/cmd_find.go +++ b/cmd/restic/cmd_find.go @@ -621,7 +621,16 @@ func runFind(ctx context.Context, opts FindOptions, gopts GlobalOptions, args [] } } + var filteredSnapshots []*restic.Snapshot for sn := range FindFilteredSnapshots(ctx, snapshotLister, repo, &opts.SnapshotFilter, opts.Snapshots) { + filteredSnapshots = append(filteredSnapshots, sn) + } + + sort.Slice(filteredSnapshots, func(i, j int) bool { + return filteredSnapshots[i].Time.Before(filteredSnapshots[j].Time) + }) + + for _, sn := range filteredSnapshots { if f.blobIDs != nil || f.treeIDs != nil { if err = f.findIDs(ctx, sn); err != nil && err.Error() != "OK" { return err