Blob Blame History Raw
From e32942895643fbd2db0055b79816e060355d6ca1 Mon Sep 17 00:00:00 2001
From: Jan Chaloupka <jchaloup@redhat.com>
Date: Tue, 21 Feb 2017 12:10:33 +0100
Subject: [PATCH] bz1350875-disaster-recovery-with-copies

---
 etcdctl/ctlv2/command/backup_command.go | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/etcdctl/ctlv2/command/backup_command.go b/etcdctl/ctlv2/command/backup_command.go
index 9c7e2ff..0ad6d7a 100644
--- a/etcdctl/ctlv2/command/backup_command.go
+++ b/etcdctl/ctlv2/command/backup_command.go
@@ -18,6 +18,7 @@ import (
 	"fmt"
 	"log"
 	"path"
+	"strconv"
 	"time"
 
 	"github.com/coreos/etcd/etcdserver/etcdserverpb"
@@ -40,6 +41,8 @@ func NewBackupCommand() cli.Command {
 			cli.StringFlag{Name: "wal-dir", Value: "", Usage: "Path to the etcd wal dir"},
 			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: "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,
 	}
@@ -99,8 +102,19 @@ func handleBackup(c *cli.Context) error {
 	var metadata etcdserverpb.Metadata
 	pbutil.MustUnmarshal(&metadata, wmetadata)
 	idgen := idutil.NewGenerator(0, time.Now())
-	metadata.NodeID = idgen.Next()
-	metadata.ClusterID = idgen.Next()
+	explicitNodeId := c.String("node-id")
+	if explicitNodeId != "" {
+		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.4