1
0
mirror of https://github.com/restic/restic.git synced 2024-06-28 08:00:52 +02:00
restic/src/cmds/restic/cmd_rebuild_index.go

39 lines
694 B
Go

package main
import (
"restic/repository"
"github.com/spf13/cobra"
)
var cmdRebuildIndex = &cobra.Command{
Use: "rebuild-index [flags]",
Short: "build a new index file",
Long: `
The "rebuild-index" command creates a new index based on the pack files in the
repository.
`,
RunE: func(cmd *cobra.Command, args []string) error {
return runRebuildIndex(globalOptions)
},
}
func init() {
cmdRoot.AddCommand(cmdRebuildIndex)
}
func runRebuildIndex(gopts GlobalOptions) error {
repo, err := OpenRepository(gopts)
if err != nil {
return err
}
lock, err := lockRepoExclusive(repo)
defer unlockRepo(lock)
if err != nil {
return err
}
return repository.RebuildIndex(repo)
}