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

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