miner restore: storage config flag

This commit is contained in:
Łukasz Magiera 2020-10-01 16:51:30 +02:00
parent 44747446a9
commit 5c33982f72

View File

@ -1,8 +1,11 @@
package main package main
import ( import (
"encoding/json"
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
"github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/config"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"io/ioutil"
"os" "os"
"github.com/docker/go-units" "github.com/docker/go-units"
@ -32,9 +35,12 @@ var initRestoreCmd = &cli.Command{
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "config", Name: "config",
Usage: "config file", Usage: "config file (config.toml)",
},
&cli.StringFlag{
Name: "storage-config",
Usage: "storage paths config (storage.json)",
}, },
// TODO: Storage paths
}, },
ArgsUsage: "[backupFile]", ArgsUsage: "[backupFile]",
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
@ -144,6 +150,33 @@ var initRestoreCmd = &cli.Command{
log.Warn("--config NOT SET, WILL USE DEFAULT VALUES") log.Warn("--config NOT SET, WILL USE DEFAULT VALUES")
} }
if cctx.IsSet("storage-config") {
log.Info("Restoring storage path config")
cf, err := homedir.Expand(cctx.String("storage-config"))
if err != nil {
return xerrors.Errorf("expanding storage config path: %w", err)
}
cfb, err := ioutil.ReadFile(cf)
if err != nil {
return xerrors.Errorf("reading storage config: %w", err)
}
var cerr error
err = lr.SetStorage(func(scfg *stores.StorageConfig) {
cerr = json.Unmarshal(cfb, scfg)
})
if cerr != nil {
return xerrors.Errorf("unmarshalling storage config: %w", cerr)
}
if err != nil {
return xerrors.Errorf("setting storage config: %w", err)
}
} else {
log.Warn("--storage-config NOT SET. NO SECTOR PATHS WILL BE CONFIGURED")
}
log.Info("Restoring metadata backup") log.Info("Restoring metadata backup")
mds, err := lr.Datastore("/metadata") mds, err := lr.Datastore("/metadata")