prysm-pulse/beacon-chain/node/clear_db.go
Preston Van Loon 7a04ff6368 Add database API for creating backups (#3694)
* Save db backup

* Fix DB backup method

* Add backup db webhook

* gaz

* if err != nil

* more verbose filename

* Don't obliterate everything :)
2019-10-03 17:29:49 +08:00

54 lines
1.1 KiB
Go

package node
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
)
func confirmDelete(d db.Database, path string) (db.Database, error) {
var clearDB bool
var err error
reader := bufio.NewReader(os.Stdin)
log.Warn("This will delete your beacon chain data base stored in your data directory. " +
"Your database backups will not be removed - do you want to proceed? (Y/N)")
for {
fmt.Print(">> ")
line, _, err := reader.ReadLine()
if err != nil {
return nil, err
}
trimmedLine := strings.TrimSpace(string(line))
lineInput := strings.ToUpper(trimmedLine)
if lineInput != "Y" && lineInput != "N" {
log.Errorf("Invalid option of %s chosen, enter Y/N", line)
continue
}
if lineInput == "Y" {
log.Warn("Deleting beaconchain.db from data directory")
clearDB = true
break
}
log.Info("Not deleting chain database, the db will be initialized" +
" with the current data directory.")
break
}
if clearDB {
if err := d.ClearDB(); err != nil {
return nil, err
}
d, err = db.NewDB(path)
if err != nil {
return nil, err
}
}
return d, nil
}