mirror of
https://git.vectorsigma.ru/public/k3s.git
synced 2026-08-01 04:39:47 +00:00
Add ability to perform an etcd on-demand snapshot via cli (#2819)
* add ability to perform an etcd on-demand snapshot via cli
(cherry picked from commit 13229019f8)
Signed-off-by: Brian Downs <brian.downs@gmail.com>
This commit is contained in:
39
pkg/cli/cmds/etcd_snapshot.go
Normal file
39
pkg/cli/cmds/etcd_snapshot.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package cmds
|
||||
|
||||
import (
|
||||
"github.com/rancher/k3s/pkg/version"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
const EtcdSnapshotCommand = "etcd-snapshot"
|
||||
|
||||
func NewEtcdSnapshotCommand(action func(*cli.Context) error) cli.Command {
|
||||
return cli.Command{
|
||||
Name: EtcdSnapshotCommand,
|
||||
Usage: "Trigger an immediate etcd snapshot",
|
||||
SkipFlagParsing: false,
|
||||
SkipArgReorder: true,
|
||||
Action: action,
|
||||
Flags: []cli.Flag{
|
||||
DebugFlag,
|
||||
LogFile,
|
||||
AlsoLogToStderr,
|
||||
cli.StringFlag{
|
||||
Name: "data-dir,d",
|
||||
Usage: "(data) Folder to hold state default /var/lib/rancher/" + version.Program + " or ${HOME}/.rancher/" + version.Program + " if not root",
|
||||
Destination: &ServerConfig.DataDir,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "(db) Set the base name of the etcd on-demand snapshot (appended with UNIX timestamp).",
|
||||
Destination: &ServerConfig.EtcdSnapshotName,
|
||||
Value: "on-demand",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "dir",
|
||||
Usage: "(db) Directory to save etcd on-demand snapshot. (default: ${data-dir}/db/snapshots)",
|
||||
Destination: &ServerConfig.EtcdSnapshotDir,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@ type Server struct {
|
||||
ClusterResetRestorePath string
|
||||
EncryptSecrets bool
|
||||
StartupHooks []func(context.Context, <-chan struct{}, string) error
|
||||
EtcdSnapshotName string
|
||||
EtcdDisableSnapshots bool
|
||||
EtcdSnapshotDir string
|
||||
EtcdSnapshotCron string
|
||||
@@ -220,6 +221,12 @@ func NewServerCommand(action func(*cli.Context) error) cli.Command {
|
||||
Usage: "(db) Disable automatic etcd snapshots",
|
||||
Destination: &ServerConfig.EtcdDisableSnapshots,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "etcd-snapshot-name",
|
||||
Usage: "(db) Set the base name of etcd snapshots. Default: etcd-snapshot-<unix-timestamp>",
|
||||
Destination: &ServerConfig.EtcdSnapshotName,
|
||||
Value: "etcd-snapshot",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "etcd-snapshot-schedule-cron",
|
||||
Usage: "(db) Snapshot interval time in cron spec. eg. every 5 hours '* */5 * * *'",
|
||||
|
||||
Reference in New Issue
Block a user