Blame SOURCES/bz1350875-disaster-recovery-with-copies.patch

634469
From 7ad700a716c2122c3b6db6677a6f717919b88926 Mon Sep 17 00:00:00 2001
634469
From: Jan Chaloupka <jchaloup@redhat.com>
634469
Date: Tue, 2 May 2017 09:56:02 +0200
634469
Subject: [PATCH] bz1350875-disaster-recovery-with-copies:
634469
634469
---
634469
 etcdctl/ctlv2/command/backup_command.go | 19 +++++++++++++++++--
634469
 1 file changed, 17 insertions(+), 2 deletions(-)
634469
634469
diff --git a/etcdctl/ctlv2/command/backup_command.go b/etcdctl/ctlv2/command/backup_command.go
634469
index feda4b1..e77791f 100644
634469
--- a/etcdctl/ctlv2/command/backup_command.go
634469
+++ b/etcdctl/ctlv2/command/backup_command.go
634469
@@ -18,6 +18,7 @@ import (
634469
 	"fmt"
634469
 	"log"
634469
 	"path/filepath"
634469
+	"strconv"
634469
 	"time"
634469
 
634469
 	"github.com/coreos/etcd/etcdserver/etcdserverpb"
634469
@@ -40,6 +41,9 @@ func NewBackupCommand() cli.Command {
634469
 			cli.StringFlag{Name: "wal-dir", Value: "", Usage: "Path to the etcd wal dir"},
634469
 			cli.StringFlag{Name: "backup-dir", Value: "", Usage: "Path to the backup dir"},
634469
 			cli.StringFlag{Name: "backup-wal-dir", Value: "", Usage: "Path to the backup wal dir"},
634469
+			cli.BoolFlag{Name: "keep-cluster-id", Usage: "Do not rewrite the cluster id"},
634469
+			cli.StringFlag{Name: "node-id", Value: "", Usage: "Use custom node id instead of a random value"},
634469
+
634469
 		},
634469
 		Action: handleBackup,
634469
 	}
634469
@@ -99,8 +103,19 @@ func handleBackup(c *cli.Context) error {
634469
 	var metadata etcdserverpb.Metadata
634469
 	pbutil.MustUnmarshal(&metadata, wmetadata)
634469
 	idgen := idutil.NewGenerator(0, time.Now())
634469
-	metadata.NodeID = idgen.Next()
634469
-	metadata.ClusterID = idgen.Next()
634469
+	explicitNodeId := c.String("node-id")
634469
+	if explicitNodeId != "" {
634469
+		metadata.NodeID, err = strconv.ParseUint(explicitNodeId, 16, 64)
634469
+		if err != nil {
634469
+			log.Fatal(err)
634469
+		}
634469
+	} else {
634469
+		metadata.NodeID = idgen.Next()
634469
+	}
634469
+	keepClusterId := c.Bool("keep-cluster-id")
634469
+	if !keepClusterId {
634469
+		metadata.ClusterID = idgen.Next()
634469
+	}
634469
 
634469
 	neww, err := wal.Create(destWAL, pbutil.MustMarshal(&metadata))
634469
 	if err != nil {
634469
-- 
634469
2.7.4
634469