From 118d599d0ac0053560262e17af3dda8eb92d770a Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Tue, 27 Dec 2022 18:25:39 +0100 Subject: [PATCH] Rename 'rebuild-index' to 'repair index' The old name still works, but is deprecated. --- cmd/restic/cmd_check.go | 2 +- cmd/restic/cmd_prune.go | 2 +- cmd/restic/cmd_repair.go | 14 ++++++++ ...d_rebuild_index.go => cmd_repair_index.go} | 36 ++++++++++++------- cmd/restic/cmd_repair_snapshots.go | 9 +---- cmd/restic/integration_test.go | 14 ++++---- doc/060_forget.rst | 2 +- doc/077_troubleshooting.rst | 12 +++---- doc/manual_rest.rst | 2 +- internal/archiver/archiver.go | 2 +- 10 files changed, 57 insertions(+), 38 deletions(-) create mode 100644 cmd/restic/cmd_repair.go rename cmd/restic/{cmd_rebuild_index.go => cmd_repair_index.go} (75%) diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index e5f29a7e5..b9f3199b2 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -245,7 +245,7 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args } if suggestIndexRebuild { - Printf("Duplicate packs/old indexes are non-critical, you can run `restic rebuild-index' to correct this.\n") + Printf("Duplicate packs/old indexes are non-critical, you can run `restic repair index' to correct this.\n") } if mixedFound { Printf("Mixed packs with tree and data blobs are non-critical, you can run `restic prune` to correct this.\n") diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index 6104002b0..1138bb55b 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -488,7 +488,7 @@ func decidePackAction(ctx context.Context, opts PruneOptions, repo restic.Reposi // Pack size does not fit and pack is needed => error // If the pack is not needed, this is no error, the pack can // and will be simply removed, see below. - Warnf("pack %s: calculated size %d does not match real size %d\nRun 'restic rebuild-index'.\n", + Warnf("pack %s: calculated size %d does not match real size %d\nRun 'restic repair index'.\n", id.Str(), p.unusedSize+p.usedSize, packSize) return errorSizeNotMatching } diff --git a/cmd/restic/cmd_repair.go b/cmd/restic/cmd_repair.go new file mode 100644 index 000000000..aefe02f3c --- /dev/null +++ b/cmd/restic/cmd_repair.go @@ -0,0 +1,14 @@ +package main + +import ( + "github.com/spf13/cobra" +) + +var cmdRepair = &cobra.Command{ + Use: "repair", + Short: "Repair the repository", +} + +func init() { + cmdRoot.AddCommand(cmdRepair) +} diff --git a/cmd/restic/cmd_rebuild_index.go b/cmd/restic/cmd_repair_index.go similarity index 75% rename from cmd/restic/cmd_rebuild_index.go rename to cmd/restic/cmd_repair_index.go index 5d70a9e12..25d6b1cab 100644 --- a/cmd/restic/cmd_rebuild_index.go +++ b/cmd/restic/cmd_repair_index.go @@ -7,15 +7,15 @@ import ( "github.com/restic/restic/internal/pack" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" - "github.com/spf13/cobra" + "github.com/spf13/pflag" ) -var cmdRebuildIndex = &cobra.Command{ - Use: "rebuild-index [flags]", +var cmdRepairIndex = &cobra.Command{ + Use: "index [flags]", Short: "Build a new index", Long: ` -The "rebuild-index" command creates a new index based on the pack files in the +The "repair index" command creates a new index based on the pack files in the repository. EXIT STATUS @@ -25,25 +25,37 @@ Exit status is 0 if the command was successful, and non-zero if there was any er `, DisableAutoGenTag: true, RunE: func(cmd *cobra.Command, args []string) error { - return runRebuildIndex(cmd.Context(), rebuildIndexOptions, globalOptions) + return runRebuildIndex(cmd.Context(), repairIndexOptions, globalOptions) }, } -// RebuildIndexOptions collects all options for the rebuild-index command. -type RebuildIndexOptions struct { +var cmdRebuildIndex = &cobra.Command{ + Use: "rebuild-index [flags]", + Short: cmdRepairIndex.Short, + Long: cmdRepairIndex.Long, + Deprecated: `Use "repair index" instead`, + DisableAutoGenTag: true, + RunE: cmdRepairIndex.RunE, +} + +// RepairIndexOptions collects all options for the repair index command. +type RepairIndexOptions struct { ReadAllPacks bool } -var rebuildIndexOptions RebuildIndexOptions +var repairIndexOptions RepairIndexOptions func init() { + cmdRepair.AddCommand(cmdRepairIndex) + // add alias for old name cmdRoot.AddCommand(cmdRebuildIndex) - f := cmdRebuildIndex.Flags() - f.BoolVar(&rebuildIndexOptions.ReadAllPacks, "read-all-packs", false, "read all pack files to generate new index from scratch") + for _, f := range []*pflag.FlagSet{cmdRepairIndex.Flags(), cmdRebuildIndex.Flags()} { + f.BoolVar(&repairIndexOptions.ReadAllPacks, "read-all-packs", false, "read all pack files to generate new index from scratch") + } } -func runRebuildIndex(ctx context.Context, opts RebuildIndexOptions, gopts GlobalOptions) error { +func runRebuildIndex(ctx context.Context, opts RepairIndexOptions, gopts GlobalOptions) error { repo, err := OpenRepository(ctx, gopts) if err != nil { return err @@ -58,7 +70,7 @@ func runRebuildIndex(ctx context.Context, opts RebuildIndexOptions, gopts Global return rebuildIndex(ctx, opts, gopts, repo, restic.NewIDSet()) } -func rebuildIndex(ctx context.Context, opts RebuildIndexOptions, gopts GlobalOptions, repo *repository.Repository, ignorePacks restic.IDSet) error { +func rebuildIndex(ctx context.Context, opts RepairIndexOptions, gopts GlobalOptions, repo *repository.Repository, ignorePacks restic.IDSet) error { var obsoleteIndexes restic.IDs packSizeFromList := make(map[restic.ID]int64) packSizeFromIndex := make(map[restic.ID]int64) diff --git a/cmd/restic/cmd_repair_snapshots.go b/cmd/restic/cmd_repair_snapshots.go index a1e6b7f61..8b9005900 100644 --- a/cmd/restic/cmd_repair_snapshots.go +++ b/cmd/restic/cmd_repair_snapshots.go @@ -10,11 +10,6 @@ import ( "github.com/spf13/cobra" ) -var cmdRepair = &cobra.Command{ - Use: "repair", - Short: "Repair commands", -} - var cmdRepairSnapshots = &cobra.Command{ Use: "snapshots [flags] [snapshot ID] [...]", Short: "Repair snapshots", @@ -27,7 +22,7 @@ be able to refit the repository. The command depends on a good state of the index, so if there are inaccurancies in the index, make sure to run -"rebuild-index" before! +"repair index" before! WARNING: @@ -66,12 +61,10 @@ type RepairOptions struct { var repairSnapshotOptions RepairOptions func init() { - cmdRoot.AddCommand(cmdRepair) cmdRepair.AddCommand(cmdRepairSnapshots) flags := cmdRepairSnapshots.Flags() initMultiSnapshotFilter(flags, &repairSnapshotOptions.SnapshotFilter, true) - flags.StringVar(&repairSnapshotOptions.AddTag, "add-tag", "repaired", "tag to add to repaired snapshots") flags.StringVar(&repairSnapshotOptions.Append, "append", ".repaired", "string to append to repaired dirs/files; remove files if empty or impossible to repair") flags.BoolVarP(&repairSnapshotOptions.DryRun, "dry-run", "n", true, "don't do anything, only show what would be done") diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 10ebbaf13..42fd26d6b 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -188,7 +188,7 @@ func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) { globalOptions.stdout = os.Stdout }() - rtest.OK(t, runRebuildIndex(context.TODO(), RebuildIndexOptions{}, gopts)) + rtest.OK(t, runRebuildIndex(context.TODO(), RepairIndexOptions{}, gopts)) } func testRunLs(t testing.TB, gopts GlobalOptions, snapshotID string) []string { @@ -1504,8 +1504,8 @@ func testRebuildIndex(t *testing.T, backendTestHook backendWrapper) { t.Fatalf("expected no error from checker for test repository, got %v", err) } - if !strings.Contains(out, "restic rebuild-index") { - t.Fatalf("did not find hint for rebuild-index command") + if !strings.Contains(out, "restic repair index") { + t.Fatalf("did not find hint for repair index command") } env.gopts.backendTestHook = backendTestHook @@ -1518,7 +1518,7 @@ func testRebuildIndex(t *testing.T, backendTestHook backendWrapper) { } if err != nil { - t.Fatalf("expected no error from checker after rebuild-index, got: %v", err) + t.Fatalf("expected no error from checker after repair index, got: %v", err) } } @@ -1599,7 +1599,7 @@ func TestRebuildIndexFailsOnAppendOnly(t *testing.T) { env.gopts.backendTestHook = func(r restic.Backend) (restic.Backend, error) { return &appendOnlyBackend{r}, nil } - err := runRebuildIndex(context.TODO(), RebuildIndexOptions{}, env.gopts) + err := runRebuildIndex(context.TODO(), RepairIndexOptions{}, env.gopts) if err == nil { t.Error("expected rebuildIndex to fail") } @@ -1887,8 +1887,8 @@ func TestListOnce(t *testing.T) { testRunPrune(t, env.gopts, pruneOpts) rtest.OK(t, runCheck(context.TODO(), checkOpts, env.gopts, nil)) - rtest.OK(t, runRebuildIndex(context.TODO(), RebuildIndexOptions{}, env.gopts)) - rtest.OK(t, runRebuildIndex(context.TODO(), RebuildIndexOptions{ReadAllPacks: true}, env.gopts)) + rtest.OK(t, runRebuildIndex(context.TODO(), RepairIndexOptions{}, env.gopts)) + rtest.OK(t, runRebuildIndex(context.TODO(), RepairIndexOptions{ReadAllPacks: true}, env.gopts)) } func TestHardLink(t *testing.T) { diff --git a/doc/060_forget.rst b/doc/060_forget.rst index 2353ef6a0..72c7ae97f 100644 --- a/doc/060_forget.rst +++ b/doc/060_forget.rst @@ -472,7 +472,7 @@ space. However, a **failed** ``prune`` run can cause the repository to become **temporarily unusable**. Therefore, make sure that you have a stable connection to the repository storage, before running this command. In case the command fails, it may become necessary to manually remove all files from the `index/` folder of the repository and -run `rebuild-index` afterwards. +run `repair index` afterwards. To prevent accidental usages of the ``--unsafe-recover-no-free-space`` option it is necessary to first run ``prune --unsafe-recover-no-free-space SOME-ID`` and then replace diff --git a/doc/077_troubleshooting.rst b/doc/077_troubleshooting.rst index 50c19565e..5b86ffd87 100644 --- a/doc/077_troubleshooting.rst +++ b/doc/077_troubleshooting.rst @@ -58,17 +58,17 @@ But make sure that your needed data is also still contained in your repository ; Note that `check` also prints out warning in some cases. These warnings point out that the repo may be optimized but is still in perfect shape and does not need any troubleshooting. -3. Index trouble -> `rebuild-index` +3. Index trouble -> `repair index` ******************************************** A common problem with broken repostories is that the index does no longer correctly represent the contents of your pack files. This is especially the case if some pack files got lost. -`rebuild-index` recovers this situation and ensures that the index exactly represents the pack files. +`repair index` recovers this situation and ensures that the index exactly represents the pack files. You might even need to manually remove corrupted pack files. In this case make sure, you run -`restic rebuild-index` after. +`restic repair index` after. -Also if you encounter problems with the index files itselves, `rebuild-index` will solve these problems +Also if you encounter problems with the index files itselves, `repair index` will solve these problems immediately. However, rebuilding the index does not solve every problem, e.g. lost pack files. @@ -91,7 +91,7 @@ backup again and check if this did heal your repository. If you realize that a specific file is broken in your repository and you have this file, any run of `backup` which includes that file will be able to heal the situation. -Note that `backup` relies on a correct index state, so make sure your index is fine or run `rebuild-index` +Note that `backup` relies on a correct index state, so make sure your index is fine or run `repair index` before running `backup`. 6. Unreferenced tree -> `recover` @@ -101,7 +101,7 @@ If for some reason you have unreferenced trees in your repository but you actual `recover` it will generate a new snapshot which allows access to all trees that you have in your repository. -Note that `recover` relies on a correct index state, so make sure your index is fine or run `rebuild-index` +Note that `recover` relies on a correct index state, so make sure your index is fine or run `repair index` before running `recover`. 7. Repair defect snapshots using `repair` diff --git a/doc/manual_rest.rst b/doc/manual_rest.rst index f812e3a70..093144722 100644 --- a/doc/manual_rest.rst +++ b/doc/manual_rest.rst @@ -35,8 +35,8 @@ Usage help is available: migrate Apply migrations mount Mount the repository prune Remove unneeded data from the repository - rebuild-index Build a new index recover Recover data from the repository not referenced by snapshots + repair Repair the repository restore Extract the data from a snapshot rewrite Rewrite snapshots to exclude unwanted files self-update Update the restic binary diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go index a56965d63..3c1cc33d0 100644 --- a/internal/archiver/archiver.go +++ b/internal/archiver/archiver.go @@ -207,7 +207,7 @@ func (arch *Archiver) wrapLoadTreeError(id restic.ID, err error) error { if arch.Repo.Index().Has(restic.BlobHandle{ID: id, Type: restic.TreeBlob}) { err = errors.Errorf("tree %v could not be loaded; the repository could be damaged: %v", id, err) } else { - err = errors.Errorf("tree %v is not known; the repository could be damaged, run `rebuild-index` to try to repair it", id) + err = errors.Errorf("tree %v is not known; the repository could be damaged, run `repair index` to try to repair it", id) } return err }