2021-01-21 21:09:15 +00:00
|
|
|
package cmds
|
|
|
|
|
|
|
|
import (
|
2021-10-15 23:46:39 +00:00
|
|
|
"time"
|
|
|
|
|
2022-03-02 23:47:27 +00:00
|
|
|
"github.com/k3s-io/k3s/pkg/version"
|
2021-01-21 21:09:15 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
const EtcdSnapshotCommand = "etcd-snapshot"
|
|
|
|
|
2021-05-07 23:10:04 +00:00
|
|
|
var EtcdSnapshotFlags = []cli.Flag{
|
|
|
|
DebugFlag,
|
2021-10-22 19:03:32 +00:00
|
|
|
ConfigFlag,
|
2021-05-07 23:10:04 +00:00
|
|
|
LogFile,
|
|
|
|
AlsoLogToStderr,
|
2023-01-31 20:57:48 +00:00
|
|
|
&cli.StringFlag{
|
2021-05-07 23:10:04 +00:00
|
|
|
Name: "node-name",
|
|
|
|
Usage: "(agent/node) Node name",
|
|
|
|
EnvVar: version.ProgramUpper + "_NODE_NAME",
|
|
|
|
Destination: &AgentConfig.NodeName,
|
|
|
|
},
|
2021-12-07 22:31:32 +00:00
|
|
|
DataDirFlag,
|
2021-11-29 18:30:04 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "dir,etcd-snapshot-dir",
|
|
|
|
Usage: "(db) Directory to save etcd on-demand snapshot. (default: ${data-dir}/db/snapshots)",
|
|
|
|
Destination: &ServerConfig.EtcdSnapshotDir,
|
|
|
|
},
|
2021-05-07 23:10:04 +00:00
|
|
|
&cli.StringFlag{
|
2021-10-22 19:03:32 +00:00
|
|
|
Name: "name",
|
2021-05-07 23:10:04 +00:00
|
|
|
Usage: "(db) Set the base name of the etcd on-demand snapshot (appended with UNIX timestamp).",
|
|
|
|
Destination: &ServerConfig.EtcdSnapshotName,
|
|
|
|
Value: "on-demand",
|
|
|
|
},
|
2022-01-14 17:31:22 +00:00
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "snapshot-compress,etcd-snapshot-compress",
|
|
|
|
Usage: "(db) Compress etcd snapshot",
|
|
|
|
Destination: &ServerConfig.EtcdSnapshotCompress,
|
|
|
|
},
|
2021-05-07 23:10:04 +00:00
|
|
|
&cli.BoolFlag{
|
2021-10-06 21:20:22 +00:00
|
|
|
Name: "s3,etcd-s3",
|
2021-05-07 23:10:04 +00:00
|
|
|
Usage: "(db) Enable backup to S3",
|
|
|
|
Destination: &ServerConfig.EtcdS3,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2021-10-06 21:20:22 +00:00
|
|
|
Name: "s3-endpoint,etcd-s3-endpoint",
|
2021-05-07 23:10:04 +00:00
|
|
|
Usage: "(db) S3 endpoint url",
|
|
|
|
Destination: &ServerConfig.EtcdS3Endpoint,
|
|
|
|
Value: "s3.amazonaws.com",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2021-10-06 21:20:22 +00:00
|
|
|
Name: "s3-endpoint-ca,etcd-s3-endpoint-ca",
|
2021-05-07 23:10:04 +00:00
|
|
|
Usage: "(db) S3 custom CA cert to connect to S3 endpoint",
|
|
|
|
Destination: &ServerConfig.EtcdS3EndpointCA,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
2021-10-06 21:20:22 +00:00
|
|
|
Name: "s3-skip-ssl-verify,etcd-s3-skip-ssl-verify",
|
2021-05-07 23:10:04 +00:00
|
|
|
Usage: "(db) Disables S3 SSL certificate validation",
|
|
|
|
Destination: &ServerConfig.EtcdS3SkipSSLVerify,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2021-10-06 21:20:22 +00:00
|
|
|
Name: "s3-access-key,etcd-s3-access-key",
|
2021-05-07 23:10:04 +00:00
|
|
|
Usage: "(db) S3 access key",
|
|
|
|
EnvVar: "AWS_ACCESS_KEY_ID",
|
|
|
|
Destination: &ServerConfig.EtcdS3AccessKey,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2021-10-06 21:20:22 +00:00
|
|
|
Name: "s3-secret-key,etcd-s3-secret-key",
|
2021-05-07 23:10:04 +00:00
|
|
|
Usage: "(db) S3 secret key",
|
|
|
|
EnvVar: "AWS_SECRET_ACCESS_KEY",
|
|
|
|
Destination: &ServerConfig.EtcdS3SecretKey,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2021-10-06 21:20:22 +00:00
|
|
|
Name: "s3-bucket,etcd-s3-bucket",
|
2021-05-07 23:10:04 +00:00
|
|
|
Usage: "(db) S3 bucket name",
|
|
|
|
Destination: &ServerConfig.EtcdS3BucketName,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2021-10-06 21:20:22 +00:00
|
|
|
Name: "s3-region,etcd-s3-region",
|
2021-05-07 23:10:04 +00:00
|
|
|
Usage: "(db) S3 region / bucket location (optional)",
|
|
|
|
Destination: &ServerConfig.EtcdS3Region,
|
|
|
|
Value: "us-east-1",
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2021-10-06 21:20:22 +00:00
|
|
|
Name: "s3-folder,etcd-s3-folder",
|
2021-05-07 23:10:04 +00:00
|
|
|
Usage: "(db) S3 folder",
|
|
|
|
Destination: &ServerConfig.EtcdS3Folder,
|
|
|
|
},
|
2021-09-05 15:56:15 +00:00
|
|
|
&cli.BoolFlag{
|
2021-10-06 21:20:22 +00:00
|
|
|
Name: "s3-insecure,etcd-s3-insecure",
|
2021-09-05 15:56:15 +00:00
|
|
|
Usage: "(db) Disables S3 over HTTPS",
|
|
|
|
Destination: &ServerConfig.EtcdS3Insecure,
|
|
|
|
},
|
2021-10-15 17:24:14 +00:00
|
|
|
&cli.DurationFlag{
|
|
|
|
Name: "s3-timeout,etcd-s3-timeout",
|
2021-10-15 23:46:39 +00:00
|
|
|
Usage: "(db) S3 timeout",
|
2021-10-15 17:24:14 +00:00
|
|
|
Destination: &ServerConfig.EtcdS3Timeout,
|
2022-07-09 01:27:05 +00:00
|
|
|
Value: 5 * time.Minute,
|
2021-10-15 17:24:14 +00:00
|
|
|
},
|
2021-05-07 23:10:04 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 19:02:05 +00:00
|
|
|
func NewEtcdSnapshotCommands(delete, list, prune, save func(ctx *cli.Context) error) cli.Command {
|
2021-01-21 21:09:15 +00:00
|
|
|
return cli.Command{
|
|
|
|
Name: EtcdSnapshotCommand,
|
|
|
|
Usage: "Trigger an immediate etcd snapshot",
|
|
|
|
SkipFlagParsing: false,
|
|
|
|
SkipArgReorder: true,
|
2022-12-05 23:28:01 +00:00
|
|
|
Subcommands: []cli.Command{
|
2023-04-19 19:02:05 +00:00
|
|
|
{
|
|
|
|
Name: "save",
|
|
|
|
Usage: "Trigger an immediate etcd snapshot",
|
|
|
|
SkipFlagParsing: false,
|
|
|
|
SkipArgReorder: true,
|
|
|
|
Action: save,
|
|
|
|
Flags: EtcdSnapshotFlags,
|
|
|
|
},
|
2022-12-05 23:28:01 +00:00
|
|
|
{
|
|
|
|
Name: "delete",
|
|
|
|
Usage: "Delete given snapshot(s)",
|
|
|
|
SkipFlagParsing: false,
|
|
|
|
SkipArgReorder: true,
|
|
|
|
Action: delete,
|
|
|
|
Flags: EtcdSnapshotFlags,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "ls",
|
|
|
|
Aliases: []string{"list", "l"},
|
|
|
|
Usage: "List snapshots",
|
|
|
|
SkipFlagParsing: false,
|
|
|
|
SkipArgReorder: true,
|
|
|
|
Action: list,
|
|
|
|
Flags: append(EtcdSnapshotFlags, &cli.StringFlag{
|
|
|
|
Name: "o,output",
|
|
|
|
Usage: "(db) List format. Default: standard. Optional: json",
|
|
|
|
Destination: &ServerConfig.EtcdListFormat,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "prune",
|
|
|
|
Usage: "Remove snapshots that match the name prefix that exceed the configured retention count",
|
|
|
|
SkipFlagParsing: false,
|
|
|
|
SkipArgReorder: true,
|
|
|
|
Action: prune,
|
|
|
|
Flags: append(EtcdSnapshotFlags, &cli.IntFlag{
|
|
|
|
Name: "snapshot-retention",
|
|
|
|
Usage: "(db) Number of snapshots to retain.",
|
|
|
|
Destination: &ServerConfig.EtcdSnapshotRetention,
|
|
|
|
Value: defaultSnapshotRentention,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-17 17:55:13 +00:00
|
|
|
},
|
2022-12-05 23:28:01 +00:00
|
|
|
Flags: EtcdSnapshotFlags,
|
2021-01-21 21:09:15 +00:00
|
|
|
}
|
|
|
|
}
|