Skip to content
Snippets Groups Projects
Unverified Commit fbdeb84b authored by Wolfgang Welz's avatar Wolfgang Welz
Browse files

add tool to recover unhealthy DBs

parent a09910ef
No related branches found
No related tags found
No related merge requests found
package main
import (
"fmt"
"os"
"github.com/iotaledger/goshimmer/packages/database"
"github.com/iotaledger/goshimmer/packages/database/prefix"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
)
const (
cfgDatabaseDir = "database"
)
func init() {
flag.String(cfgDatabaseDir, "mainnetdb", "path to the database folder")
}
func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
}
func run() error {
flag.Parse()
err := viper.BindPFlags(flag.CommandLine)
if err != nil {
return err
}
dbDir := viper.GetString(cfgDatabaseDir)
ok, err := exists(dbDir)
if err != nil {
return err
}
if !ok {
return fmt.Errorf("database folder does not exist: %s", dbDir)
}
db, err := database.NewDB(dbDir)
if err != nil {
return err
}
healthStore := db.NewStore().WithRealm([]byte{prefix.DBPrefixHealth})
return healthStore.Delete([]byte("db_health"))
}
func exists(path string) (bool, error) {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, err
}
return true, err
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment