From df5ee4abdc73ceaa1a585ea72aa61633e069e736 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Mon, 12 Jul 2021 17:59:28 +0300 Subject: [PATCH] cli: allow to use incremental dumps in `db restore` Signed-off-by: Evgeniy Stratonikov --- cli/server/server.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cli/server/server.go b/cli/server/server.go index e0899ec52..73416907e 100644 --- a/cli/server/server.go +++ b/cli/server/server.go @@ -64,6 +64,10 @@ func NewCommands() []cli.Command { Name: "dump", Usage: "directory for storing JSON dumps", }, + cli.BoolFlag{ + Name: "incremental, n", + Usage: "use if dump is incremental", + }, ) return []cli.Command{ { @@ -240,6 +244,16 @@ func restoreDB(ctx *cli.Context) error { defer prometheus.ShutDown() defer pprof.ShutDown() + var start uint32 + if ctx.Bool("incremental") { + start = reader.ReadU32LE() + if chain.BlockHeight()+1 < start { + return cli.NewExitError(fmt.Errorf("expected height: %d, dump starts at %d", + chain.BlockHeight()+1, start), 1) + } + skip = chain.BlockHeight() + 1 - start + } + var allBlocks = reader.ReadU32LE() if reader.Err != nil { return cli.NewExitError(err, 1)