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

1d4225
From 2109f199de8a5af1e33ebd79f90fff0969f72a50 Mon Sep 17 00:00:00 2001
e4deaa
From: Jan Chaloupka <jchaloup@redhat.com>
1d4225
Date: Tue, 8 Jan 2019 10:53:19 +0100
1d4225
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
1d4225
index 82e61d8..d7aceed 100644
e4deaa
--- a/etcdctl/ctlv2/command/backup_command.go
e4deaa
+++ b/etcdctl/ctlv2/command/backup_command.go
1d4225
@@ -21,6 +21,7 @@ import (
1d4225
 	"path"
f67c12
 	"path/filepath"
1d4225
 	"regexp"
e4deaa
+	"strconv"
e4deaa
 	"time"
e4deaa
 
e4deaa
 	"github.com/coreos/etcd/etcdserver/etcdserverpb"
1d4225
@@ -48,6 +49,8 @@ func NewBackupCommand() cli.Command {
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"},
1d4225
 			cli.BoolFlag{Name: "with-v3", Usage: "Backup v3 backend data"},
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"},
e4deaa
 		},
e4deaa
 		Action: handleBackup,
e4deaa
 	}
1d4225
@@ -83,8 +86,20 @@ func handleBackup(c *cli.Context) error {
1d4225
 	saveDB(filepath.Join(destSnap, "db"), filepath.Join(srcSnap, "db"), state.Commit, withV3)
1d4225
 
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 != "" {
1d4225
+		var err error
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
-- 
1d4225
2.7.5
e4deaa