-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/urfave/cli/v2" | ||
"github.com/spf13/cobra" | ||
"go.uber.org/zap" | ||
|
||
"github.com/spacemeshos/go-spacemesh/cmd/merge-nodes/internal" | ||
) | ||
|
||
var version string | ||
|
||
func init() { | ||
rootCmd.Flags().StringP("from", "f", "", | ||
"The `data` folder to read identities from and merge into `to`") | ||
rootCmd.MarkFlagRequired("from") | ||
rootCmd.Flags().StringP("to", "t", "", | ||
"The `data` folder to write the merged node to. Can be an existing remote node or empty.") | ||
rootCmd.MarkFlagRequired("to") | ||
} | ||
|
||
func main() { | ||
cfg := zap.NewProductionConfig() | ||
cfg.Encoding = "console" | ||
dbLog, err := cfg.Build() | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
fmt.Println("create logger:", err) | ||
os.Exit(1) | ||
} | ||
defer dbLog.Sync() | ||
|
||
app := &cli.App{ | ||
Name: "Spacemesh Node Merger", | ||
Usage: "Merge identities of two Spacemesh nodes into one.\n" + | ||
"The `from` node will be merged into the `to` node, leaving the `from` node untouched.\n" + | ||
"The `to` node can be an existing node or an empty folder.\n" + | ||
"Be sure to backup the `to` node before running this command.\n" + | ||
"NOTE: both `from` and `to` nodes must be upgraded to the latest version before running this command.\n" + | ||
"NOTE: after upgrading and starting the nodes at least once, convert them to remote nodes before merging.", | ||
Version: version, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "from", | ||
Aliases: []string{"f"}, | ||
Usage: "The `data` folder to read identities from and merge into `to`", | ||
Required: true, | ||
}, | ||
&cli.StringFlag{ | ||
Name: "to", | ||
Aliases: []string{"t"}, | ||
Usage: "The `data` folder to write the merged node to. Can be an existing remote node or empty.", | ||
Required: true, | ||
}, | ||
}, | ||
Action: func(ctx *cli.Context) error { | ||
return internal.MergeDBs(ctx.Context, dbLog, ctx.String("from"), ctx.String("to")) | ||
}, | ||
} | ||
} | ||
|
||
if err := app.Run(os.Args); err != nil { | ||
dbLog.Sugar().Warnln("app run:", err) | ||
os.Exit(1) | ||
} | ||
var rootCmd = &cobra.Command{ | ||
Use: "merge-nodes -f <dir> -t <dir>", | ||
Short: "Spacemesh Node Merger", | ||
Long: `Merge identities of two Spacemesh nodes into one. | ||
The 'from' node will be merged into the 'to' node, leaving the 'from' node untouched. | ||
The 'to' node can be an existing node or an empty folder. | ||
Be sure to backup the 'to' node before running this command. | ||
NOTE: both 'from' and 'to' nodes must be upgraded to the latest version before running this command. | ||
NOTE: after upgrading and starting the nodes at least once, convert them to remote nodes before merging.`, | ||
Version: version, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
cfg := zap.NewProductionConfig() | ||
cfg.Encoding = "console" | ||
dbLog, err := cfg.Build() | ||
if err != nil { | ||
log.Fatalf("create logger: %v", err) | ||
} | ||
defer dbLog.Sync() | ||
|
||
f := cmd.Flag("from").Value.String() | ||
t := cmd.Flag("to").Value.String() | ||
|
||
return internal.MergeDBs(cmd.Context(), dbLog, f, t) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters