From ede57bf951a46175fc11d98887dd3758c9e1964a Mon Sep 17 00:00:00 2001 From: liuxu Date: Mon, 6 Nov 2023 14:24:11 +0800 Subject: [PATCH] fix: backup script doesn't work when set etcd dataDir to another dir except '/var/lib/etcd' --- cmd/kk/pkg/etcd/tasks.go | 1 + cmd/kk/pkg/etcd/templates/backup_script.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/cmd/kk/pkg/etcd/tasks.go b/cmd/kk/pkg/etcd/tasks.go index 052991e5..0aeaccdd 100644 --- a/cmd/kk/pkg/etcd/tasks.go +++ b/cmd/kk/pkg/etcd/tasks.go @@ -406,6 +406,7 @@ func (b *BackupETCD) Execute(runtime connector.Runtime) error { Data: util.Data{ "Hostname": runtime.RemoteHost().GetName(), "Etcdendpoint": fmt.Sprintf("https://%s:2379", runtime.RemoteHost().GetInternalAddress()), + "DataDir": b.KubeConf.Cluster.Etcd.DataDir, "Backupdir": b.KubeConf.Cluster.Etcd.BackupDir, "KeepbackupNumber": b.KubeConf.Cluster.Etcd.KeepBackupNumber + 1, "EtcdBackupScriptDir": b.KubeConf.Cluster.Etcd.BackupScriptDir, diff --git a/cmd/kk/pkg/etcd/templates/backup_script.go b/cmd/kk/pkg/etcd/templates/backup_script.go index c3a09ebe..9445aff1 100644 --- a/cmd/kk/pkg/etcd/templates/backup_script.go +++ b/cmd/kk/pkg/etcd/templates/backup_script.go @@ -32,7 +32,11 @@ set -o pipefail ETCDCTL_PATH='/usr/local/bin/etcdctl' ENDPOINTS='{{ .Etcdendpoint }}' +{{- if .DataDir }} +ETCD_DATA_DIR="{{ .DataDir }}" +{{- else }} ETCD_DATA_DIR="/var/lib/etcd" +{{- end }} BACKUP_DIR="{{ .Backupdir }}/etcd-$(date +%Y-%m-%d-%H-%M-%S)" KEEPBACKUPNUMBER='{{ .KeepbackupNumber }}' ETCDBACKUPSCIPT='{{ .EtcdBackupScriptDir }}'