From 045aa6455805e98f4c3f0d6d4d9a5479fc82e0c7 Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Sat, 21 Oct 2023 16:16:06 -0300 Subject: [PATCH 1/3] cmd/copy: Prefix hostname to snapshot display output This change better resembles the output generated by `Snapshot.String()`, which includes both username and hostname. Closes #4506 Before: ``` $ restic copy --from-repo /srv/restic-repo repository 3666882b opened (version 2, compression level auto) repository 0085c387 opened (version 2, compression level auto) created new cache in /home/mike/.cache/restic [0:00] 100.00% 1 / 1 index files loaded [0:00] 0 index files loaded snapshot 32b39a20 of [/home/mike/data] at 2023-10-21 16:01:13.979948154 -0300 -03) copy started, this may take a while... [0:00] 100.00% 1 / 1 packs copied snapshot 10331fdd saved ``` After: ``` $ restic copy --from-repo /srv/restic-repo repository 3666882b opened (version 2, compression level auto) repository 0085c387 opened (version 2, compression level auto) [0:00] 100.00% 1 / 1 index files loaded [0:00] 0 index files loaded snapshot 32b39a20 of [/home/mike/data] at 2023-10-21 16:01:13.979948154 -0300 -03 by mike@desktop) copy started, this may take a while... [0:00] 100.00% 1 / 1 packs copied snapshot a67bd1ee saved ``` --- cmd/restic/cmd_copy.go | 5 +++-- cmd/restic/cmd_ls.go | 2 +- cmd/restic/cmd_repair_snapshots.go | 2 +- cmd/restic/cmd_rewrite.go | 2 +- doc/045_working_with_repos.rst | 10 +++++----- doc/077_troubleshooting.rst | 2 +- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index 0cf96a092..11e3a555f 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -126,11 +126,12 @@ func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args [] if sn.Original != nil { srcOriginal = *sn.Original } + if originalSns, ok := dstSnapshotByOriginal[srcOriginal]; ok { isCopy := false for _, originalSn := range originalSns { if similarSnapshots(originalSn, sn) { - Verboseff("\nsnapshot %s of %v at %s)\n", sn.ID().Str(), sn.Paths, sn.Time) + Verboseff("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) Verboseff("skipping source snapshot %s, was already copied to snapshot %s\n", sn.ID().Str(), originalSn.ID().Str()) isCopy = true break @@ -140,7 +141,7 @@ func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args [] continue } } - Verbosef("\nsnapshot %s of %v at %s)\n", sn.ID().Str(), sn.Paths, sn.Time) + Verbosef("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) Verbosef(" copy started, this may take a while...\n") if err := copyTree(ctx, srcRepo, dstRepo, visitedTrees, *sn.Tree, gopts.Quiet); err != nil { return err diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index 5b3984eb2..504e6a0fa 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -207,7 +207,7 @@ func runLs(ctx context.Context, opts LsOptions, gopts GlobalOptions, args []stri } } else { printSnapshot = func(sn *restic.Snapshot) { - Verbosef("snapshot %s of %v filtered by %v at %s):\n", sn.ID().Str(), sn.Paths, dirs, sn.Time) + Verbosef("snapshot %s of %v filtered by %v at %s by %s@%s):\n", sn.ID().Str(), sn.Paths, dirs, sn.Time, sn.Username, sn.Hostname) } printNode = func(path string, node *restic.Node) { Printf("%s\n", formatNode(path, node, lsOptions.ListLong, lsOptions.HumanReadable)) diff --git a/cmd/restic/cmd_repair_snapshots.go b/cmd/restic/cmd_repair_snapshots.go index 786097132..82cb7eede 100644 --- a/cmd/restic/cmd_repair_snapshots.go +++ b/cmd/restic/cmd_repair_snapshots.go @@ -144,7 +144,7 @@ func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOpt changedCount := 0 for sn := range FindFilteredSnapshots(ctx, snapshotLister, repo, &opts.SnapshotFilter, args) { - Verbosef("\nsnapshot %s of %v at %s)\n", sn.ID().Str(), sn.Paths, sn.Time) + Verbosef("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) changed, err := filterAndReplaceSnapshot(ctx, repo, sn, func(ctx context.Context, sn *restic.Snapshot) (restic.ID, error) { return rewriter.RewriteTree(ctx, repo, "/", *sn.Tree) diff --git a/cmd/restic/cmd_rewrite.go b/cmd/restic/cmd_rewrite.go index afd80aca1..d31d26685 100644 --- a/cmd/restic/cmd_rewrite.go +++ b/cmd/restic/cmd_rewrite.go @@ -290,7 +290,7 @@ func runRewrite(ctx context.Context, opts RewriteOptions, gopts GlobalOptions, a changedCount := 0 for sn := range FindFilteredSnapshots(ctx, snapshotLister, repo, &opts.SnapshotFilter, args) { - Verbosef("\nsnapshot %s of %v at %s)\n", sn.ID().Str(), sn.Paths, sn.Time) + Verbosef("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) changed, err := rewriteSnapshot(ctx, repo, sn, opts) if err != nil { return errors.Fatalf("unable to rewrite snapshot ID %q: %v", sn.ID().Str(), err) diff --git a/doc/045_working_with_repos.rst b/doc/045_working_with_repos.rst index 68c181fa2..2fe8d1d8d 100644 --- a/doc/045_working_with_repos.rst +++ b/doc/045_working_with_repos.rst @@ -94,11 +94,11 @@ example from a local to a remote repository, you can use the ``copy`` command: repository d6504c63 opened successfully, password is correct repository 3dd0878c opened successfully, password is correct - snapshot 410b18a2 of [/home/user/work] at 2020-06-09 23:15:57.305305 +0200 CEST) + snapshot 410b18a2 of [/home/user/work] at 2020-06-09 23:15:57.305305 +0200 CEST by user@kasimir) copy started, this may take a while... snapshot 7a746a07 saved - snapshot 4e5d5487 of [/home/user/work] at 2020-05-01 22:44:07.012113 +0200 CEST) + snapshot 4e5d5487 of [/home/user/work] at 2020-05-01 22:44:07.012113 +0200 CEST by user@kasimir) skipping snapshot 4e5d5487, was already copied to snapshot 50eb62b7 The example command copies all snapshots from the source repository @@ -193,18 +193,18 @@ the unwanted files from affected snapshots by rewriting them using the $ restic -r /srv/restic-repo rewrite --exclude secret-file repository c881945a opened (repository version 2) successfully, password is correct - snapshot 6160ddb2 of [/home/user/work] at 2022-06-12 16:01:28.406630608 +0200 CEST) + snapshot 6160ddb2 of [/home/user/work] at 2022-06-12 16:01:28.406630608 +0200 CEST by user@kasimir) excluding /home/user/work/secret-file saved new snapshot b6aee1ff - snapshot 4fbaf325 of [/home/user/work] at 2022-05-01 11:22:26.500093107 +0200 CEST) + snapshot 4fbaf325 of [/home/user/work] at 2022-05-01 11:22:26.500093107 +0200 CEST by user@kasimir) modified 1 snapshots $ restic -r /srv/restic-repo rewrite --exclude secret-file 6160ddb2 repository c881945a opened (repository version 2) successfully, password is correct - snapshot 6160ddb2 of [/home/user/work] at 2022-06-12 16:01:28.406630608 +0200 CEST) + snapshot 6160ddb2 of [/home/user/work] at 2022-06-12 16:01:28.406630608 +0200 CEST by user@kasimir) excluding /home/user/work/secret-file new snapshot saved as b6aee1ff diff --git a/doc/077_troubleshooting.rst b/doc/077_troubleshooting.rst index fe317acfc..baf0be65c 100644 --- a/doc/077_troubleshooting.rst +++ b/doc/077_troubleshooting.rst @@ -153,7 +153,7 @@ command will automatically remove the original, damaged snapshots. $ restic repair snapshots --forget - snapshot 6979421e of [/home/user/restic/restic] at 2022-11-02 20:59:18.617503315 +0100 CET) + snapshot 6979421e of [/home/user/restic/restic] at 2022-11-02 20:59:18.617503315 +0100 CET by user@host) file "/restic/internal/fuse/snapshots_dir.go": removed missing content file "/restic/internal/restorer/restorer_unix_test.go": removed missing content file "/restic/internal/walker/walker.go": removed missing content From 33b7c84a7a323519be4b1b5f7a2ca3393748ba44 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 6 Jan 2024 20:19:17 +0100 Subject: [PATCH 2/3] deduplicate string formatting of snapshot metadata This removes the spurious ")" bracket at the end and normalizes the metadata format used by the `ls` command. --- cmd/restic/cmd_copy.go | 4 ++-- cmd/restic/cmd_ls.go | 2 +- cmd/restic/cmd_repair_snapshots.go | 2 +- cmd/restic/cmd_rewrite.go | 2 +- internal/restic/snapshot.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/restic/cmd_copy.go b/cmd/restic/cmd_copy.go index 11e3a555f..92922b42b 100644 --- a/cmd/restic/cmd_copy.go +++ b/cmd/restic/cmd_copy.go @@ -131,7 +131,7 @@ func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args [] isCopy := false for _, originalSn := range originalSns { if similarSnapshots(originalSn, sn) { - Verboseff("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) + Verboseff("\n%v\n", sn) Verboseff("skipping source snapshot %s, was already copied to snapshot %s\n", sn.ID().Str(), originalSn.ID().Str()) isCopy = true break @@ -141,7 +141,7 @@ func runCopy(ctx context.Context, opts CopyOptions, gopts GlobalOptions, args [] continue } } - Verbosef("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) + Verbosef("\n%v\n", sn) Verbosef(" copy started, this may take a while...\n") if err := copyTree(ctx, srcRepo, dstRepo, visitedTrees, *sn.Tree, gopts.Quiet); err != nil { return err diff --git a/cmd/restic/cmd_ls.go b/cmd/restic/cmd_ls.go index 504e6a0fa..83a03559d 100644 --- a/cmd/restic/cmd_ls.go +++ b/cmd/restic/cmd_ls.go @@ -207,7 +207,7 @@ func runLs(ctx context.Context, opts LsOptions, gopts GlobalOptions, args []stri } } else { printSnapshot = func(sn *restic.Snapshot) { - Verbosef("snapshot %s of %v filtered by %v at %s by %s@%s):\n", sn.ID().Str(), sn.Paths, dirs, sn.Time, sn.Username, sn.Hostname) + Verbosef("%v filtered by %v:\n", sn, dirs) } printNode = func(path string, node *restic.Node) { Printf("%s\n", formatNode(path, node, lsOptions.ListLong, lsOptions.HumanReadable)) diff --git a/cmd/restic/cmd_repair_snapshots.go b/cmd/restic/cmd_repair_snapshots.go index 82cb7eede..19e457b1f 100644 --- a/cmd/restic/cmd_repair_snapshots.go +++ b/cmd/restic/cmd_repair_snapshots.go @@ -144,7 +144,7 @@ func runRepairSnapshots(ctx context.Context, gopts GlobalOptions, opts RepairOpt changedCount := 0 for sn := range FindFilteredSnapshots(ctx, snapshotLister, repo, &opts.SnapshotFilter, args) { - Verbosef("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) + Verbosef("\n%v\n", sn) changed, err := filterAndReplaceSnapshot(ctx, repo, sn, func(ctx context.Context, sn *restic.Snapshot) (restic.ID, error) { return rewriter.RewriteTree(ctx, repo, "/", *sn.Tree) diff --git a/cmd/restic/cmd_rewrite.go b/cmd/restic/cmd_rewrite.go index d31d26685..d55e6137b 100644 --- a/cmd/restic/cmd_rewrite.go +++ b/cmd/restic/cmd_rewrite.go @@ -290,7 +290,7 @@ func runRewrite(ctx context.Context, opts RewriteOptions, gopts GlobalOptions, a changedCount := 0 for sn := range FindFilteredSnapshots(ctx, snapshotLister, repo, &opts.SnapshotFilter, args) { - Verbosef("\nsnapshot %s of %v at %s by %s@%s)\n", sn.ID().Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) + Verbosef("\n%v\n", sn) changed, err := rewriteSnapshot(ctx, repo, sn, opts) if err != nil { return errors.Fatalf("unable to rewrite snapshot ID %q: %v", sn.ID().Str(), err) diff --git a/internal/restic/snapshot.go b/internal/restic/snapshot.go index 13e795ec8..88171a646 100644 --- a/internal/restic/snapshot.go +++ b/internal/restic/snapshot.go @@ -96,7 +96,7 @@ func ForAllSnapshots(ctx context.Context, be Lister, loader LoaderUnpacked, excl } func (sn Snapshot) String() string { - return fmt.Sprintf("", + return fmt.Sprintf("snapshot %s of %v at %s by %s@%s", sn.id.Str(), sn.Paths, sn.Time, sn.Username, sn.Hostname) } From c7844530d81a1fd074293e180f4ca434dcab098b Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sat, 6 Jan 2024 20:25:24 +0100 Subject: [PATCH 3/3] update docs --- doc/045_working_with_repos.rst | 12 ++++++------ doc/077_troubleshooting.rst | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/045_working_with_repos.rst b/doc/045_working_with_repos.rst index 2fe8d1d8d..d74c9c240 100644 --- a/doc/045_working_with_repos.rst +++ b/doc/045_working_with_repos.rst @@ -94,11 +94,11 @@ example from a local to a remote repository, you can use the ``copy`` command: repository d6504c63 opened successfully, password is correct repository 3dd0878c opened successfully, password is correct - snapshot 410b18a2 of [/home/user/work] at 2020-06-09 23:15:57.305305 +0200 CEST by user@kasimir) + snapshot 410b18a2 of [/home/user/work] at 2020-06-09 23:15:57.305305 +0200 CEST by user@kasimir copy started, this may take a while... snapshot 7a746a07 saved - snapshot 4e5d5487 of [/home/user/work] at 2020-05-01 22:44:07.012113 +0200 CEST by user@kasimir) + snapshot 4e5d5487 of [/home/user/work] at 2020-05-01 22:44:07.012113 +0200 CEST by user@kasimir skipping snapshot 4e5d5487, was already copied to snapshot 50eb62b7 The example command copies all snapshots from the source repository @@ -193,18 +193,18 @@ the unwanted files from affected snapshots by rewriting them using the $ restic -r /srv/restic-repo rewrite --exclude secret-file repository c881945a opened (repository version 2) successfully, password is correct - snapshot 6160ddb2 of [/home/user/work] at 2022-06-12 16:01:28.406630608 +0200 CEST by user@kasimir) + snapshot 6160ddb2 of [/home/user/work] at 2022-06-12 16:01:28.406630608 +0200 CEST by user@kasimir excluding /home/user/work/secret-file saved new snapshot b6aee1ff - snapshot 4fbaf325 of [/home/user/work] at 2022-05-01 11:22:26.500093107 +0200 CEST by user@kasimir) + snapshot 4fbaf325 of [/home/user/work] at 2022-05-01 11:22:26.500093107 +0200 CEST by user@kasimir modified 1 snapshots $ restic -r /srv/restic-repo rewrite --exclude secret-file 6160ddb2 repository c881945a opened (repository version 2) successfully, password is correct - snapshot 6160ddb2 of [/home/user/work] at 2022-06-12 16:01:28.406630608 +0200 CEST by user@kasimir) + snapshot 6160ddb2 of [/home/user/work] at 2022-06-12 16:01:28.406630608 +0200 CEST by user@kasimir excluding /home/user/work/secret-file new snapshot saved as b6aee1ff @@ -247,7 +247,7 @@ This is possible using the ``rewrite`` command with the option ``--new-host`` fo repository b7dbade3 opened (version 2, compression level auto) [0:00] 100.00% 1 / 1 index files loaded - snapshot 8ed674f4 of [/path/to/abc.txt] at 2023-11-27 21:57:52.439139291 +0100 CET) + snapshot 8ed674f4 of [/path/to/abc.txt] at 2023-11-27 21:57:52.439139291 +0100 CET by user@kasimir setting time to 1999-01-01 11:11:11 +0100 CET setting host to newhost saved new snapshot c05da643 diff --git a/doc/077_troubleshooting.rst b/doc/077_troubleshooting.rst index baf0be65c..6a9a6ee15 100644 --- a/doc/077_troubleshooting.rst +++ b/doc/077_troubleshooting.rst @@ -153,7 +153,7 @@ command will automatically remove the original, damaged snapshots. $ restic repair snapshots --forget - snapshot 6979421e of [/home/user/restic/restic] at 2022-11-02 20:59:18.617503315 +0100 CET by user@host) + snapshot 6979421e of [/home/user/restic/restic] at 2022-11-02 20:59:18.617503315 +0100 CET by user@host file "/restic/internal/fuse/snapshots_dir.go": removed missing content file "/restic/internal/restorer/restorer_unix_test.go": removed missing content file "/restic/internal/walker/walker.go": removed missing content