command: automatically migrate raft data on start
This commit is contained in:
parent
41aa5aeb09
commit
4f4f5fa7d5
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue