From 2109f199de8a5af1e33ebd79f90fff0969f72a50 Mon Sep 17 00:00:00 2001
From: Jan Chaloupka <jchaloup@redhat.com>
Date: Tue, 8 Jan 2019 10:53:19 +0100
Subject: [PATCH] bz1350875-disaster-recovery-with-copies
---
etcdctl/ctlv2/command/backup_command.go | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/etcdctl/ctlv2/command/backup_command.go b/etcdctl/ctlv2/command/backup_command.go
index 82e61d8..d7aceed 100644
--- a/etcdctl/ctlv2/command/backup_command.go
+++ b/etcdctl/ctlv2/command/backup_command.go
@@ -21,6 +21,7 @@ import (
"path"
"path/filepath"
"regexp"
+ "strconv"
"time"
"github.com/coreos/etcd/etcdserver/etcdserverpb"
@@ -48,6 +49,8 @@ func NewBackupCommand() cli.Command {
cli.StringFlag{Name: "backup-dir", Value: "", Usage: "Path to the backup dir"},
cli.StringFlag{Name: "backup-wal-dir", Value: "", Usage: "Path to the backup wal dir"},
cli.BoolFlag{Name: "with-v3", Usage: "Backup v3 backend data"},
+ cli.BoolFlag{Name: "keep-cluster-id", Usage: "Do not rewrite the cluster id"},
+ cli.StringFlag{Name: "node-id", Value: "", Usage: "Use custom node id instead of a random value"},
},
Action: handleBackup,
}
@@ -83,8 +86,20 @@ func handleBackup(c *cli.Context) error {
saveDB(filepath.Join(destSnap, "db"), filepath.Join(srcSnap, "db"), state.Commit, withV3)
idgen := idutil.NewGenerator(0, time.Now())
- metadata.NodeID = idgen.Next()
- metadata.ClusterID = idgen.Next()
+ explicitNodeId := c.String("node-id")
+ if explicitNodeId != "" {
+ var err error
+ metadata.NodeID, err = strconv.ParseUint(explicitNodeId, 16, 64)
+ if err != nil {
+ log.Fatal(err)
+ }
+ } else {
+ metadata.NodeID = idgen.Next()
+ }
+ keepClusterId := c.Bool("keep-cluster-id")
+ if !keepClusterId {
+ metadata.ClusterID = idgen.Next()
+ }
neww, err := wal.Create(destWAL, pbutil.MustMarshal(&metadata))
if err != nil {
--
2.7.5