pull/18680/head
absolutelightning 1 year ago
parent ac867d67e8
commit e8f4bfe7a0

@ -36,7 +36,7 @@ type cmd struct {
func (c *cmd) getAppendFileNameFlag() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.Var(&c.appendFileNameFlag, "append-filename", "Append filename flag supports the following "+
"comma-separated arguments. 1. version, 2. dc. 3. node 4. status. It appends these values to the filename provided in the command")
"comma-separated arguments. 1. version, 2. dc. It appends these values to the filename provided in the command")
return fs
}
@ -75,7 +75,9 @@ func (c *cmd) Run(args []string) int {
if len(appendFileNameFlags) != 0 && len(c.appendFileNameFlag.String()) > 0 {
agentSelfResponse, err := client.Agent().Self()
if err != nil {
operatorHealthResponse, error := client.Operator().AutopilotServerHealth(nil)
if err != nil && error != nil {
c.UI.Error(fmt.Sprintf("Error connecting to Consul agent and fetching datacenter/version: %s", err))
return 1
}
@ -99,29 +101,6 @@ func (c *cmd) Run(args []string) int {
}
}
if slices.Contains(appendFileNameFlags, "node") {
if config, ok := agentSelfResponse["Config"]; ok {
if nodeName, ok := config["NodeName"]; ok {
fileNameWithoutExt = fileNameWithoutExt + "-" + nodeName.(string)
}
}
}
if slices.Contains(appendFileNameFlags, "status") {
if status, ok := agentSelfResponse["Stats"]; ok {
if config, ok := status["consul"]; ok {
configMap := config.(map[string]interface{})
if leader, ok := configMap["leader"]; ok {
if leader == "true" {
fileNameWithoutExt = fileNameWithoutExt + "-" + "leader"
} else {
fileNameWithoutExt = fileNameWithoutExt + "-" + "follower"
}
}
}
}
}
//adding extension back
file = fileNameWithoutExt + fileExt
}

@ -77,20 +77,19 @@ $ consul snapshot save -stale backup.snap
# ...
```
To create snapshot file with consul version, datacenter, node name and leader/follower info,
run
This is useful for situations where a cluster is in a degraded state and no
leader is available. To target a specific server for a snapshot, you can run
the `consul snapshot save` command on that specific server.
To create snapshot file with consul version and datacenter run
```shell-session
$ consul snapshot save -append-filename node,status,version,dc backup.snap
$ consul snapshot save -append-filename version,dc backup.snap
#...
```
File name created will be like backup-%CONSUL_VERSION%-%DC_NAME%-%NODE_NAME%-%STATUS.snap
File name created will be like backup-%CONSUL_VERSION%-%DC_NAME%.snap
example - backup-1.17.0-dc1-local-machine-leader.tgz
This is useful for situations where a cluster is in a degraded state and no
leader is available. To target a specific server for a snapshot, you can run
the `consul snapshot save` command on that specific server.
Please see the [HTTP API](/consul/api-docs/snapshot) documentation for
more details about snapshot internals.

Loading…
Cancel
Save