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,
|
|
|
|
cli.StringFlag{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
func NewEtcdSnapshotCommand(action func(*cli.Context) error, subcommands []cli.Command) 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,
|
|
|
|
Action: action,
|
2021-05-07 23:10:04 +00:00
|
|
|
Subcommands: subcommands,
|
2021-11-29 18:30:04 +00:00
|
|
|
Flags: EtcdSnapshotFlags,
|
2021-05-07 23:10:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-17 17:55:13 +00:00
|
|
|
func NewEtcdSnapshotSubcommands(delete, list, prune, save func(ctx *cli.Context) error) []cli.Command {
|
2021-05-07 23:10:04 +00:00
|
|
|
return []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "delete",
|
|
|
|
Usage: "Delete given snapshot(s)",
|
|
|
|
SkipFlagParsing: false,
|
|
|
|
SkipArgReorder: true,
|
|
|
|
Action: delete,
|
|
|
|
Flags: EtcdSnapshotFlags,
|
2021-01-21 21:09:15 +00:00
|
|
|
},
|
2021-05-11 23:59:33 +00:00
|
|
|
{
|
|
|
|
Name: "ls",
|
|
|
|
Aliases: []string{"list", "l"},
|
2021-05-13 20:36:33 +00:00
|
|
|
Usage: "List snapshots",
|
2021-05-11 23:59:33 +00:00
|
|
|
SkipFlagParsing: false,
|
|
|
|
SkipArgReorder: true,
|
|
|
|
Action: list,
|
2022-02-25 21:00:00 +00:00
|
|
|
Flags: append(EtcdSnapshotFlags, &cli.StringFlag{
|
|
|
|
Name: "o,output",
|
|
|
|
Usage: "(db) List format. Default: standard. Optional: json",
|
|
|
|
Destination: &ServerConfig.EtcdListFormat,
|
|
|
|
}),
|
2021-05-11 23:59:33 +00:00
|
|
|
},
|
2021-05-13 20:36:33 +00:00
|
|
|
{
|
|
|
|
Name: "prune",
|
2021-11-29 18:30:04 +00:00
|
|
|
Usage: "Remove snapshots that match the name prefix that exceed the configured retention count",
|
2021-05-13 20:36:33 +00:00
|
|
|
SkipFlagParsing: false,
|
|
|
|
SkipArgReorder: true,
|
|
|
|
Action: prune,
|
|
|
|
Flags: append(EtcdSnapshotFlags, &cli.IntFlag{
|
|
|
|
Name: "snapshot-retention",
|
2021-07-26 16:59:33 +00:00
|
|
|
Usage: "(db) Number of snapshots to retain.",
|
2021-05-13 20:36:33 +00:00
|
|
|
Destination: &ServerConfig.EtcdSnapshotRetention,
|
|
|
|
Value: defaultSnapshotRentention,
|
|
|
|
}),
|
|
|
|
},
|
2021-05-17 17:55:13 +00:00
|
|
|
{
|
|
|
|
Name: "save",
|
|
|
|
Usage: "Trigger an immediate etcd snapshot",
|
|
|
|
SkipFlagParsing: false,
|
|
|
|
SkipArgReorder: true,
|
|
|
|
Action: save,
|
2021-11-29 18:30:04 +00:00
|
|
|
Flags: EtcdSnapshotFlags,
|
2021-05-17 17:55:13 +00:00
|
|
|
},
|
2021-01-21 21:09:15 +00:00
|
|
|
}
|
|
|
|
}
|