From 7ad700a716c2122c3b6db6677a6f717919b88926 Mon Sep 17 00:00:00 2001
From: Jan Chaloupka <jchaloup@redhat.com>
Date: Tue, 2 May 2017 09:56:02 +0200
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 feda4b1..e77791f 100644
--- a/etcdctl/ctlv2/command/backup_command.go
+++ b/etcdctl/ctlv2/command/backup_command.go
@@ -18,6 +18,7 @@ import (
 	"fmt"
 	"log"
 	"path/filepath"
+	"strconv"
 	"time"
 
 	"github.com/coreos/etcd/etcdserver/etcdserverpb"
@@ -40,6 +41,9 @@ 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 +103,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

