diff --git a/charts/tidb-backup/templates/scripts/_start_backup.sh.tpl b/charts/tidb-backup/templates/scripts/_start_backup.sh.tpl index 8c6c8e8843..38f7b5bf35 100644 --- a/charts/tidb-backup/templates/scripts/_start_backup.sh.tpl +++ b/charts/tidb-backup/templates/scripts/_start_backup.sh.tpl @@ -6,12 +6,18 @@ dirname=/data/${BACKUP_NAME} echo "making dir ${dirname}" mkdir -p ${dirname} -gc_life_time=`/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} -p${TIDB_PASSWORD} -Nse "select variable_value from mysql.tidb where variable_name='tikv_gc_life_time';"` +password_str="" +if [ -n "${TIDB_PASSWORD}" ]; +then + password_str="-p${TIDB_PASSWORD}" +fi + +gc_life_time=`/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} ${password_str} -Nse "select variable_value from mysql.tidb where variable_name='tikv_gc_life_time';"` echo "Old TiKV GC life time is ${gc_life_time}" echo "Increase TiKV GC life time to 3h" -/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} -p${TIDB_PASSWORD} -Nse "update mysql.tidb set variable_value='3h' where variable_name='tikv_gc_life_time';" -/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} -p${TIDB_PASSWORD} -Nse "select variable_name,variable_value from mysql.tidb where variable_name='tikv_gc_life_time';" +/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} ${password_str} -Nse "update mysql.tidb set variable_value='3h' where variable_name='tikv_gc_life_time';" +/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} ${password_str} -Nse "select variable_name,variable_value from mysql.tidb where variable_name='tikv_gc_life_time';" if [ -n "{{ .Values.initialCommitTs }}" ]; then @@ -31,8 +37,8 @@ fi {{ .Values.backupOptions }} ${snapshot_args:-} echo "Reset TiKV GC life time to ${gc_life_time}" -/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} -p${TIDB_PASSWORD} -Nse "update mysql.tidb set variable_value='${gc_life_time}' where variable_name='tikv_gc_life_time';" -/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} -p${TIDB_PASSWORD} -Nse "select variable_name,variable_value from mysql.tidb where variable_name='tikv_gc_life_time';" +/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} ${password_str} -Nse "update mysql.tidb set variable_value='${gc_life_time}' where variable_name='tikv_gc_life_time';" +/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} ${password_str} -Nse "select variable_name,variable_value from mysql.tidb where variable_name='tikv_gc_life_time';" {{- if .Values.gcp }} uploader \ diff --git a/charts/tidb-backup/templates/scripts/_start_restore.sh.tpl b/charts/tidb-backup/templates/scripts/_start_restore.sh.tpl index e32c57d105..1489630a81 100644 --- a/charts/tidb-backup/templates/scripts/_start_restore.sh.tpl +++ b/charts/tidb-backup/templates/scripts/_start_restore.sh.tpl @@ -30,8 +30,14 @@ downloader \ --destDir=/data {{- end }} +password_str="" +if [ -n "${TIDB_PASSWORD}" ]; +then + password_str="-p${TIDB_PASSWORD}" +fi + count=1 -while ! mysql -u ${TIDB_USER} -h `eval echo '${'$host'}'` -P 4000 -p${TIDB_PASSWORD} -e 'select version();' +while ! mysql -u ${TIDB_USER} -h `eval echo '${'$host'}'` -P 4000 ${password_str} -e 'select version();' do echo "waiting for tidb, retry ${count} times ..." sleep 10 diff --git a/charts/tidb-cluster/templates/scripts/_start_scheduled_backup.sh.tpl b/charts/tidb-cluster/templates/scripts/_start_scheduled_backup.sh.tpl index 632237adff..bca4afb048 100755 --- a/charts/tidb-cluster/templates/scripts/_start_scheduled_backup.sh.tpl +++ b/charts/tidb-cluster/templates/scripts/_start_scheduled_backup.sh.tpl @@ -10,12 +10,18 @@ backupPath=/data/${backupName} echo "making dir ${backupPath}" mkdir -p ${backupPath} -gc_life_time=`/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} -p${TIDB_PASSWORD} -Nse "select variable_value from mysql.tidb where variable_name='tikv_gc_life_time';"` +password_str="" +if [ -n "${TIDB_PASSWORD}" ]; +then + password_str="-p${TIDB_PASSWORD}" +fi + +gc_life_time=`/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} ${password_str} -Nse "select variable_value from mysql.tidb where variable_name='tikv_gc_life_time';"` echo "Old TiKV GC life time is ${gc_life_time}" echo "Increase TiKV GC life time to 3h" -/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} -p${TIDB_PASSWORD} -Nse "update mysql.tidb set variable_value='3h' where variable_name='tikv_gc_life_time';" -/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} -p${TIDB_PASSWORD} -Nse "select variable_name,variable_value from mysql.tidb where variable_name='tikv_gc_life_time';" +/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} ${password_str} -Nse "update mysql.tidb set variable_value='3h' where variable_name='tikv_gc_life_time';" +/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} ${password_str} -Nse "select variable_name,variable_value from mysql.tidb where variable_name='tikv_gc_life_time';" /mydumper \ --outputdir=${backupPath} \ @@ -29,8 +35,8 @@ echo "Increase TiKV GC life time to 3h" {{ .Values.scheduledBackup.options }} echo "Reset TiKV GC life time to ${gc_life_time}" -/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} -p${TIDB_PASSWORD} -Nse "update mysql.tidb set variable_value='${gc_life_time}' where variable_name='tikv_gc_life_time';" -/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} -p${TIDB_PASSWORD} -Nse "select variable_name,variable_value from mysql.tidb where variable_name='tikv_gc_life_time';" +/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} ${password_str} -Nse "update mysql.tidb set variable_value='${gc_life_time}' where variable_name='tikv_gc_life_time';" +/usr/bin/mysql -h${host} -P4000 -u${TIDB_USER} ${password_str} -Nse "select variable_name,variable_value from mysql.tidb where variable_name='tikv_gc_life_time';" {{- if .Values.scheduledBackup.gcp }} uploader \ diff --git a/tests/actions.go b/tests/actions.go index 846ca8dce8..bc8bc06820 100644 --- a/tests/actions.go +++ b/tests/actions.go @@ -565,6 +565,11 @@ func (oa *operatorActions) CleanTidbCluster(info *TidbClusterConfig) error { return fmt.Errorf("failed to delete dir pod %v", err) } + err = oa.kubeCli.CoreV1().Secrets(info.Namespace).Delete(info.InitSecretName, &metav1.DeleteOptions{}) + if err != nil && !errors.IsNotFound(err) { + return fmt.Errorf("failed to delete secret: %s, %v", info.InitSecretName, err) + } + setStr := label.New().Instance(info.ClusterName).String() resources := []string{"pvc"} @@ -1722,9 +1727,13 @@ func (oa *operatorActions) DeployAdHocBackup(info *TidbClusterConfig) error { oa.EmitEvent(info, "DeployAdHocBackup") glog.Infof("begin to deploy adhoc backup cluster[%s] namespace[%s]", info.ClusterName, info.Namespace) - getTSCmd := fmt.Sprintf("set -euo pipefail; mysql -u%s -p%s -h%s-tidb.%s -P 4000 -Nse 'show master status;' | awk '{print $2}'", + passwdStr := "" + if info.Password != "" { + passwdStr = fmt.Sprintf("-p%s", info.Password) + } + getTSCmd := fmt.Sprintf("set -euo pipefail; mysql -u%s %s -h%s-tidb.%s -P 4000 -Nse 'show master status;' | awk '{print $2}'", info.UserName, - info.Password, + passwdStr, info.ClusterName, info.Namespace, ) diff --git a/tests/cmd/e2e/main.go b/tests/cmd/e2e/main.go index 97b3ac3eaa..331bdf8904 100644 --- a/tests/cmd/e2e/main.go +++ b/tests/cmd/e2e/main.go @@ -84,7 +84,7 @@ func main() { TiKVImage: fmt.Sprintf("pingcap/tikv:%s", initTidbVersion), TiDBImage: fmt.Sprintf("pingcap/tidb:%s", initTidbVersion), StorageClassName: "local-storage", - Password: "admin", + Password: "", UserName: "root", InitSecretName: fmt.Sprintf("%s-set-secret", name1), BackupSecretName: fmt.Sprintf("%s-backup-secret", name1),