mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package db
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v3/beacon-chain/db/kv"
|
|
"github.com/prysmaticlabs/prysm/v3/cmd"
|
|
"github.com/prysmaticlabs/prysm/v3/io/file"
|
|
"github.com/prysmaticlabs/prysm/v3/io/prompt"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
const dbExistsYesNoPrompt = "A database file already exists in the target directory. " +
|
|
"Are you sure that you want to overwrite it? [y/n]"
|
|
|
|
// Restore a beacon chain database.
|
|
func Restore(cliCtx *cli.Context) error {
|
|
sourceFile := cliCtx.String(cmd.RestoreSourceFileFlag.Name)
|
|
targetDir := cliCtx.String(cmd.RestoreTargetDirFlag.Name)
|
|
|
|
restoreDir := path.Join(targetDir, kv.BeaconNodeDbDirName)
|
|
if file.FileExists(path.Join(restoreDir, kv.DatabaseFileName)) {
|
|
resp, err := prompt.ValidatePrompt(
|
|
os.Stdin, dbExistsYesNoPrompt, prompt.ValidateYesOrNo,
|
|
)
|
|
if err != nil {
|
|
return errors.Wrap(err, "could not validate choice")
|
|
}
|
|
if strings.EqualFold(resp, "n") {
|
|
log.Info("Restore aborted")
|
|
return nil
|
|
}
|
|
}
|
|
if err := file.MkdirAll(restoreDir); err != nil {
|
|
return err
|
|
}
|
|
if err := file.CopyFile(sourceFile, path.Join(restoreDir, kv.DatabaseFileName)); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Info("Restore completed successfully")
|
|
return nil
|
|
}
|