From 4f4f5fa7d5f302a263f0ed34ef4c622f24f003f8 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Thu, 9 Apr 2015 22:58:35 -0700 Subject: [PATCH] command: automatically migrate raft data on start --- command/agent/command.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/command/agent/command.go b/command/agent/command.go index dfc548393..58e23b600 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -15,6 +15,7 @@ import ( "time" "github.com/armon/go-metrics" + "github.com/hashicorp/consul-migrate/migrator" "github.com/hashicorp/consul/watch" "github.com/hashicorp/go-checkpoint" "github.com/hashicorp/go-syslog" @@ -597,6 +598,28 @@ func (c *Command) Run(args []string) int { metrics.NewGlobal(metricsConf, inm) } + // If we are starting a consul 0.5.1+ server for the first time, + // and we have data from a previous Consul version, attempt to + // migrate the data from LMDB to BoltDB using the migrator utility. + if config.Server { + m, err := migrator.New(config.DataDir) + if err != nil { + c.Ui.Error(err.Error()) + return 1 + } + + start := time.Now() + migrated, err := m.Migrate() + if err != nil { + c.Ui.Error(fmt.Sprintf("Failed to migrate raft data: %s", err)) + return 1 + } + if migrated { + duration := time.Now().Sub(start) + c.Ui.Output(fmt.Sprintf("Successfully migrated raft data in %s", duration)) + } + } + // Create the agent if err := c.setupAgent(config, logOutput, logWriter); err != nil { return 1