mirror of
https://github.com/octoleo/restic.git
synced 2024-11-27 23:36:40 +00:00
Rename 'rebuild-index' to 'repair index'
The old name still works, but is deprecated.
This commit is contained in:
parent
db459eda21
commit
118d599d0a
@ -245,7 +245,7 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts GlobalOptions, args
|
|||||||
}
|
}
|
||||||
|
|
||||||
if suggestIndexRebuild {
|
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 {
|
if mixedFound {
|
||||||
Printf("Mixed packs with tree and data blobs are non-critical, you can run `restic prune` to correct this.\n")
|
Printf("Mixed packs with tree and data blobs are non-critical, you can run `restic prune` to correct this.\n")
|
||||||
|
@ -488,7 +488,7 @@ func decidePackAction(ctx context.Context, opts PruneOptions, repo restic.Reposi
|
|||||||
// Pack size does not fit and pack is needed => error
|
// Pack size does not fit and pack is needed => error
|
||||||
// If the pack is not needed, this is no error, the pack can
|
// If the pack is not needed, this is no error, the pack can
|
||||||
// and will be simply removed, see below.
|
// 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)
|
id.Str(), p.unusedSize+p.usedSize, packSize)
|
||||||
return errorSizeNotMatching
|
return errorSizeNotMatching
|
||||||
}
|
}
|
||||||
|
14
cmd/restic/cmd_repair.go
Normal file
14
cmd/restic/cmd_repair.go
Normal file
@ -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)
|
||||||
|
}
|
@ -7,15 +7,15 @@ import (
|
|||||||
"github.com/restic/restic/internal/pack"
|
"github.com/restic/restic/internal/pack"
|
||||||
"github.com/restic/restic/internal/repository"
|
"github.com/restic/restic/internal/repository"
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdRebuildIndex = &cobra.Command{
|
var cmdRepairIndex = &cobra.Command{
|
||||||
Use: "rebuild-index [flags]",
|
Use: "index [flags]",
|
||||||
Short: "Build a new index",
|
Short: "Build a new index",
|
||||||
Long: `
|
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.
|
repository.
|
||||||
|
|
||||||
EXIT STATUS
|
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,
|
DisableAutoGenTag: true,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
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.
|
var cmdRebuildIndex = &cobra.Command{
|
||||||
type RebuildIndexOptions struct {
|
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
|
ReadAllPacks bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var rebuildIndexOptions RebuildIndexOptions
|
var repairIndexOptions RepairIndexOptions
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
cmdRepair.AddCommand(cmdRepairIndex)
|
||||||
|
// add alias for old name
|
||||||
cmdRoot.AddCommand(cmdRebuildIndex)
|
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)
|
repo, err := OpenRepository(ctx, gopts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -58,7 +70,7 @@ func runRebuildIndex(ctx context.Context, opts RebuildIndexOptions, gopts Global
|
|||||||
return rebuildIndex(ctx, opts, gopts, repo, restic.NewIDSet())
|
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
|
var obsoleteIndexes restic.IDs
|
||||||
packSizeFromList := make(map[restic.ID]int64)
|
packSizeFromList := make(map[restic.ID]int64)
|
||||||
packSizeFromIndex := make(map[restic.ID]int64)
|
packSizeFromIndex := make(map[restic.ID]int64)
|
@ -10,11 +10,6 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmdRepair = &cobra.Command{
|
|
||||||
Use: "repair",
|
|
||||||
Short: "Repair commands",
|
|
||||||
}
|
|
||||||
|
|
||||||
var cmdRepairSnapshots = &cobra.Command{
|
var cmdRepairSnapshots = &cobra.Command{
|
||||||
Use: "snapshots [flags] [snapshot ID] [...]",
|
Use: "snapshots [flags] [snapshot ID] [...]",
|
||||||
Short: "Repair snapshots",
|
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
|
The command depends on a good state of the index, so if
|
||||||
there are inaccurancies in the index, make sure to run
|
there are inaccurancies in the index, make sure to run
|
||||||
"rebuild-index" before!
|
"repair index" before!
|
||||||
|
|
||||||
|
|
||||||
WARNING:
|
WARNING:
|
||||||
@ -66,12 +61,10 @@ type RepairOptions struct {
|
|||||||
var repairSnapshotOptions RepairOptions
|
var repairSnapshotOptions RepairOptions
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmdRoot.AddCommand(cmdRepair)
|
|
||||||
cmdRepair.AddCommand(cmdRepairSnapshots)
|
cmdRepair.AddCommand(cmdRepairSnapshots)
|
||||||
flags := cmdRepairSnapshots.Flags()
|
flags := cmdRepairSnapshots.Flags()
|
||||||
|
|
||||||
initMultiSnapshotFilter(flags, &repairSnapshotOptions.SnapshotFilter, true)
|
initMultiSnapshotFilter(flags, &repairSnapshotOptions.SnapshotFilter, true)
|
||||||
|
|
||||||
flags.StringVar(&repairSnapshotOptions.AddTag, "add-tag", "repaired", "tag to add to repaired snapshots")
|
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.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")
|
flags.BoolVarP(&repairSnapshotOptions.DryRun, "dry-run", "n", true, "don't do anything, only show what would be done")
|
||||||
|
@ -188,7 +188,7 @@ func testRunRebuildIndex(t testing.TB, gopts GlobalOptions) {
|
|||||||
globalOptions.stdout = os.Stdout
|
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 {
|
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)
|
t.Fatalf("expected no error from checker for test repository, got %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(out, "restic rebuild-index") {
|
if !strings.Contains(out, "restic repair index") {
|
||||||
t.Fatalf("did not find hint for rebuild-index command")
|
t.Fatalf("did not find hint for repair index command")
|
||||||
}
|
}
|
||||||
|
|
||||||
env.gopts.backendTestHook = backendTestHook
|
env.gopts.backendTestHook = backendTestHook
|
||||||
@ -1518,7 +1518,7 @@ func testRebuildIndex(t *testing.T, backendTestHook backendWrapper) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
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) {
|
env.gopts.backendTestHook = func(r restic.Backend) (restic.Backend, error) {
|
||||||
return &appendOnlyBackend{r}, nil
|
return &appendOnlyBackend{r}, nil
|
||||||
}
|
}
|
||||||
err := runRebuildIndex(context.TODO(), RebuildIndexOptions{}, env.gopts)
|
err := runRebuildIndex(context.TODO(), RepairIndexOptions{}, env.gopts)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("expected rebuildIndex to fail")
|
t.Error("expected rebuildIndex to fail")
|
||||||
}
|
}
|
||||||
@ -1887,8 +1887,8 @@ func TestListOnce(t *testing.T) {
|
|||||||
testRunPrune(t, env.gopts, pruneOpts)
|
testRunPrune(t, env.gopts, pruneOpts)
|
||||||
rtest.OK(t, runCheck(context.TODO(), checkOpts, env.gopts, nil))
|
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(), RepairIndexOptions{}, env.gopts))
|
||||||
rtest.OK(t, runRebuildIndex(context.TODO(), RebuildIndexOptions{ReadAllPacks: true}, env.gopts))
|
rtest.OK(t, runRebuildIndex(context.TODO(), RepairIndexOptions{ReadAllPacks: true}, env.gopts))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHardLink(t *testing.T) {
|
func TestHardLink(t *testing.T) {
|
||||||
|
@ -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
|
**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
|
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
|
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
|
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
|
necessary to first run ``prune --unsafe-recover-no-free-space SOME-ID`` and then replace
|
||||||
|
@ -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
|
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.
|
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
|
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.
|
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
|
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.
|
immediately.
|
||||||
|
|
||||||
However, rebuilding the index does not solve every problem, e.g. lost pack files.
|
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
|
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.
|
`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`.
|
before running `backup`.
|
||||||
|
|
||||||
6. Unreferenced tree -> `recover`
|
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
|
`recover` it will generate a new snapshot which allows access to all trees that you have in your
|
||||||
repository.
|
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`.
|
before running `recover`.
|
||||||
|
|
||||||
7. Repair defect snapshots using `repair`
|
7. Repair defect snapshots using `repair`
|
||||||
|
@ -35,8 +35,8 @@ Usage help is available:
|
|||||||
migrate Apply migrations
|
migrate Apply migrations
|
||||||
mount Mount the repository
|
mount Mount the repository
|
||||||
prune Remove unneeded data from 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
|
recover Recover data from the repository not referenced by snapshots
|
||||||
|
repair Repair the repository
|
||||||
restore Extract the data from a snapshot
|
restore Extract the data from a snapshot
|
||||||
rewrite Rewrite snapshots to exclude unwanted files
|
rewrite Rewrite snapshots to exclude unwanted files
|
||||||
self-update Update the restic binary
|
self-update Update the restic binary
|
||||||
|
@ -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}) {
|
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)
|
err = errors.Errorf("tree %v could not be loaded; the repository could be damaged: %v", id, err)
|
||||||
} else {
|
} 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
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user