1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-01 15:19:09 +00:00

Allow local backup for rancher

This commit is contained in:
moelsayed 2019-01-14 22:20:10 +02:00 committed by Alena Prokharchyk
parent 82fa8d6305
commit cf037b1ed6
2 changed files with 19 additions and 16 deletions

View File

@ -130,14 +130,13 @@ func validateServicesOptions(c *Cluster) error {
func validateEtcdBackupOptions(c *Cluster) error {
if c.Services.Etcd.BackupConfig != nil {
if c.Services.Etcd.BackupConfig.S3BackupConfig == nil {
return fmt.Errorf("etcd backup is enabled but no s3 backend is specified")
}
if len(c.Services.Etcd.BackupConfig.S3BackupConfig.Endpoint) == 0 {
return fmt.Errorf("etcd s3 backup backend endpoint can't be empty")
}
if len(c.Services.Etcd.BackupConfig.S3BackupConfig.BucketName) == 0 {
return fmt.Errorf("etcd s3 backup backend bucketName can't be empty")
if c.Services.Etcd.BackupConfig.S3BackupConfig != nil {
if len(c.Services.Etcd.BackupConfig.S3BackupConfig.Endpoint) == 0 {
return fmt.Errorf("etcd s3 backup backend endpoint can't be empty")
}
if len(c.Services.Etcd.BackupConfig.S3BackupConfig.BucketName) == 0 {
return fmt.Errorf("etcd s3 backup backend bucketName can't be empty")
}
}
}
return nil

View File

@ -275,7 +275,7 @@ func RunEtcdSnapshotSave(ctx context.Context, etcdHost *hosts.Host, prsMap map[s
imageCfg.Cmd = append(imageCfg.Cmd, "--creation="+es.Creation)
}
if es.BackupConfig != nil && es.BackupConfig.S3BackupConfig != nil {
if es.BackupConfig != nil {
imageCfg = configS3BackupImgCmd(ctx, imageCfg, es.BackupConfig)
}
hostCfg := &container.HostConfig{
@ -447,17 +447,21 @@ func GetEtcdSnapshotChecksum(ctx context.Context, etcdHost *hosts.Host, prsMap m
}
func configS3BackupImgCmd(ctx context.Context, imageCfg *container.Config, bc *v3.BackupConfig) *container.Config {
log.Infof(ctx, "Invoking s3 backup server cmd config, bucketName:%s, endpoint:%s", bc.S3BackupConfig.BucketName, bc.S3BackupConfig.Endpoint)
cmd := []string{
"--s3-backup=true",
"--s3-endpoint=" + bc.S3BackupConfig.Endpoint,
"--s3-accessKey=" + bc.S3BackupConfig.AccessKey,
"--s3-secretKey=" + bc.S3BackupConfig.SecretKey,
"--s3-bucketName=" + bc.S3BackupConfig.BucketName,
"--s3-region=" + bc.S3BackupConfig.Region,
"--creation=" + fmt.Sprintf("%dh", bc.IntervalHours),
"--retention=" + fmt.Sprintf("%dh", bc.Retention*bc.IntervalHours),
}
if bc.S3BackupConfig != nil {
cmd = append(cmd, []string{
"--s3-backup=true",
"--s3-endpoint=" + bc.S3BackupConfig.Endpoint,
"--s3-accessKey=" + bc.S3BackupConfig.AccessKey,
"--s3-secretKey=" + bc.S3BackupConfig.SecretKey,
"--s3-bucketName=" + bc.S3BackupConfig.BucketName,
"--s3-region=" + bc.S3BackupConfig.Region,
}...)
}
imageCfg.Cmd = append(imageCfg.Cmd, cmd...)
return imageCfg
}