Skip to content

Commit 94ac812

Browse files
committed
Revert "feat(backend): dbbackup备份空间预测优化 close #1825"
This reverts commit f566d7c.
1 parent 4324582 commit 94ac812

File tree

13 files changed

+292
-105
lines changed

13 files changed

+292
-105
lines changed

dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/install_new_dbbackup.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,6 @@ func (i *InstallNewDbBackupComp) ChownGroup() (err error) {
452452
return nil
453453
}
454454

455-
// saveTplConfigfile 渲染ini模板
456-
// todo: 将 Configs 转换成 struct,再把 struct 转换成 ini. 方便渲染 Public.EncryptOpt
457455
func (i *InstallNewDbBackupComp) saveTplConfigfile(tmpl string) (err error) {
458456
f, err := os.OpenFile(tmpl, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0755)
459457
if err != nil {
@@ -462,31 +460,20 @@ func (i *InstallNewDbBackupComp) saveTplConfigfile(tmpl string) (err error) {
462460
defer func() {
463461
_ = f.Close()
464462
}()
465-
var encryptOpt = make(map[string]string)
466-
var encryptOptPrefix = "EncryptOpt"
467-
for key, val := range i.Params.Configs {
468-
_, err := fmt.Fprintf(f, "[%s]\n", key)
463+
464+
for k, v := range i.Params.Configs {
465+
_, err := fmt.Fprintf(f, "[%s]\n", k)
469466
if err != nil {
470-
return errors.WithMessagef(err, "写配置模版 %s 失败", key)
467+
return errors.WithMessagef(err, "写配置模版 %s 失败", k)
471468
}
472-
for k, v := range val {
473-
if strings.HasPrefix(k, encryptOptPrefix+".") {
474-
encryptOpt[strings.TrimPrefix(k, encryptOptPrefix+".")] = v
475-
continue
476-
}
469+
for k, v := range v {
477470
_, err := fmt.Fprintf(f, "%s = %s\n", k, v)
478471
if err != nil {
479472
return errors.WithMessagef(err, "写配置模版 %s, %s 失败", k, v)
480473
}
481474
}
482475
fmt.Fprintf(f, "\n")
483476
}
484-
if len(encryptOpt) > 0 {
485-
fmt.Fprintf(f, "[%s]\n", encryptOptPrefix)
486-
for k, v := range encryptOpt {
487-
fmt.Fprintf(f, "%s = %s\n", k, v)
488-
}
489-
}
490477
return
491478
}
492479

dbm-services/mysql/db-tools/mysql-dbbackup/Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
DIST = $(error please set DIST flag to txsql or community)
12
PROJ_BIN="dbbackup"
23
PROJ="dbbackup-go"
34
MODULE="dbm-services/mysql/db-tools/mysql-dbbackup"
45
VERSION = $(error please set VERSION flag)
5-
DIST = $(error please set DIST flag to txsql or community)
66
GITHASH = ""
77
OUTPUT_DIR = build
88
PKG_DIR=${OUTPUT_DIR}/${PROJ}
99
PROJ_PKG=${PROJ}-${DIST}.tar.gz
10-
PROJ_PKG_DEPS=dbbackup-go-deps-${DIST}
1110
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.gitHash=${GITHASH} "
1211
DEV_BUILD_FLAG = "-X ${MODULE}/cmd.version="develop" -X ${MODULE}/cmd.gitHash="" "
1312
BASE_DIR = $(shell pwd)
@@ -20,17 +19,16 @@ build:
2019

2120
.PHONY: package
2221
package:build
23-
echo "Packaging ${PROJ_PKG} using dependency ${PROJ_PKG_DEPS}"
22+
echo "Packaging ${PROJ_PKG}"
2423
mkdir -p ${PKG_DIR}
2524
cp ${OUTPUT_DIR}/${PROJ_BIN} ${PKG_DIR}/
2625
cp mydumper_for_tdbctl.cnf ${PKG_DIR}/
2726
cp dbbackup_main.sh ${PKG_DIR}/
28-
rm -rf ${PROJ_PKG_DEPS} && tar -zxf ${PROJ_PKG_DEPS}.tar.gz
29-
cp -r ${PROJ_PKG_DEPS}/* ${PKG_DIR}/
27+
cp -r dbbackup-go-deps/* ${PKG_DIR}/
3028
chmod +x ${PKG_DIR}/*.sh && chmod +x ${PKG_DIR}/dbbackup
3129
chmod +x ${PKG_DIR}/bin/* && chmod +x ${PKG_DIR}/bin/*/*
30+
3231
tar -C ${OUTPUT_DIR} -zcvf ${OUTPUT_DIR}/${PROJ_PKG} ${PROJ}
33-
md5sum ${OUTPUT_DIR}/${PROJ_PKG}
3432

3533
.PHONY: clean
3634
clean:
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# release_type only used for release package name
4+
# we use dependency dir 'dbbackup-go-deps/' to tar, so make sure this dir has correct deps
5+
6+
#### precheck section
7+
usage() {
8+
echo "Usage:"
9+
echo "./build.sh [-s] [-t your_release_type]"
10+
echo -e "Description:\n"
11+
echo " -s: skip go build, use build/dbbackup binary"
12+
echo " -t: set release_type, allowed: txsql,community"
13+
echo ""
14+
exit 1
15+
}
16+
17+
release_type=""
18+
go_build=1
19+
while getopts 't:sh' OPT; do
20+
case $OPT in
21+
t)
22+
release_type="$OPTARG"
23+
;;
24+
s)
25+
go_build=0
26+
;;
27+
h) usage;;
28+
?) usage;;
29+
esac
30+
done
31+
if [ "$release_type" != "txsql" -a "$release_type" != "community" ];then
32+
echo "unknown release_type. allowed: txsql,community"
33+
exit 1
34+
else
35+
echo "release_type=$release_type"
36+
fi
37+
38+
#### build section
39+
proj_bin=dbbackup
40+
build_dir=build
41+
proj=dbbackup-go
42+
pkg_dir=${build_dir}/${proj}
43+
proj_pkg=${proj}-${release_type}.tar.gz
44+
45+
if [ $go_build -ne 0 ];then
46+
echo "run go build"
47+
rm -rf $pkg_dir ; mkdir -p $pkg_dir
48+
rm -f ${build_dir}/${proj_bin}
49+
go build -o ${build_dir}/${proj_bin}
50+
if [ $? -gt 0 ];then
51+
echo "build dbbackup failed"
52+
exit 1
53+
fi
54+
else
55+
echo "skip run go build. use binary build/dbbackup"
56+
rm -rf $pkg_dir ; mkdir -p $pkg_dir
57+
if [ ! -f ${build_dir}/${proj_bin} ];then
58+
echo "${build_dir}/${proj_bin} not exists"
59+
exit 1
60+
fi
61+
fi
62+
63+
cp -r dbbackup-go-deps/* ${pkg_dir}/
64+
if [ $? -gt 0 ];then
65+
echo "copy dbbackup-go-deps failed"
66+
exit 1
67+
fi
68+
69+
cp -a dbbackup_main.sh ${pkg_dir}/
70+
cp -a mydumper_for_tdbctl.cnf ${pkg_dir}/
71+
cp -a ${build_dir}/${proj_bin} ${pkg_dir}/
72+
chmod +x ${pkg_dir}/*.sh && chmod +x ${pkg_dir}/dbbackup
73+
chmod +x ${pkg_dir}/bin/* && chmod +x ${pkg_dir}/bin/*/*
74+
75+
tar -C ${build_dir} -zcvf ${build_dir}/${proj_pkg} ${proj}

dbm-services/mysql/db-tools/mysql-dbbackup/cmd/subcmd_version.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

dbm-services/mysql/db-tools/mysql-dbbackup/pkg/config/config.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,27 @@ type BackupConfig struct {
99
PhysicalBackup PhysicalBackup `ini:"PhysicalBackup"`
1010
PhysicalLoad PhysicalLoad `ini:"PhysicalLoad"`
1111
}
12+
13+
/*
14+
// LogicalBackupCnf Logical Backup BackupConfig
15+
type LogicalBackupCnf struct {
16+
Public Public `ini:"Public" validate:"required"`
17+
LogicalBackup LogicalBackup `ini:"LogicalBackup" validate:"required"`
18+
}
19+
20+
// LogicalLoadCnf Logical Load BackupConfig
21+
type LogicalLoadCnf struct {
22+
LogicalBackup LogicalBackup `ini:"LogicalBackup" validate:"required"`
23+
}
24+
25+
// PhysicalBackupCnf Physical Backup BackupConfig
26+
type PhysicalBackupCnf struct {
27+
Public Public `ini:"Public" validate:"required"`
28+
PhysicalBackup PhysicalBackup `ini:"PhysicalBackup" validate:"required"`
29+
}
30+
31+
// PhysicalLoadCnf Physical Load BackupConfig
32+
type PhysicalLoadCnf struct {
33+
PhysicalLoad PhysicalLoad `ini:"PhysicalLoad" validate:"required"`
34+
}
35+
*/

dbm-services/mysql/db-tools/mysql-dbbackup/pkg/src/backupexe/dumper.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212

1313
// Dumper TODO
1414
type Dumper interface {
15-
initConfig(mysqlVersion string) error
15+
initConfig() error
1616
Execute(enableTimeOut bool) error
1717
}
1818

19-
// BuildDumper return logical or physical dumper
19+
// BuildDumper TODO
2020
func BuildDumper(cnf *config.BackupConfig) (dumper Dumper, err error) {
2121
if strings.ToLower(cnf.Public.BackupType) == "logical" {
2222
if err := validate.GoValidateStruct(cnf.LogicalBackup, false, false); err != nil {
@@ -29,6 +29,7 @@ func BuildDumper(cnf *config.BackupConfig) (dumper Dumper, err error) {
2929
if err := validate.GoValidateStruct(cnf.PhysicalBackup, false, false); err != nil {
3030
return nil, err
3131
}
32+
3233
dumper = &PhysicalDumper{
3334
cnf: cnf,
3435
}
@@ -37,5 +38,6 @@ func BuildDumper(cnf *config.BackupConfig) (dumper Dumper, err error) {
3738
err := fmt.Errorf("unknown BackupType: %s", cnf.Public.BackupType)
3839
return nil, err
3940
}
41+
4042
return dumper, nil
4143
}

dbm-services/mysql/db-tools/mysql-dbbackup/pkg/src/backupexe/dumper_logical.go

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type LogicalDumper struct {
2121
dbbackupHome string
2222
}
2323

24-
func (l *LogicalDumper) initConfig(mysqlVersion string) error {
24+
func (l *LogicalDumper) initConfig() error {
2525
if l.cnf == nil {
2626
return errors.New("logical dumper params is nil")
2727
}
@@ -34,6 +34,82 @@ func (l *LogicalDumper) initConfig(mysqlVersion string) error {
3434
return nil
3535
}
3636

37+
// CreateDumpCmd Create LogicalBackup Cmd
38+
//func (l *LogicalDumper) CreateDumpCmd() (string, error) {
39+
//var buffer bytes.Buffer
40+
//binpath := filepath.Join(l.dbbackupHome, "/bin/mydumper")
41+
//buffer.WriteString(binpath)
42+
//buffer.WriteString(" -h " + l.cnf.Public.MysqlHost)
43+
//buffer.WriteString(" -P " + l.cnf.Public.MysqlPort)
44+
//buffer.WriteString(" -u " + l.cnf.Public.MysqlUser)
45+
//buffer.WriteString(" -p " + l.cnf.Public.MysqlPasswd)
46+
//buffer.WriteString(" -o " + l.cnf.Public.BackupDir + "/" + common.TargetName)
47+
//if !l.cnf.LogicalBackup.DisableCompress {
48+
// buffer.WriteString(" --compress")
49+
//}
50+
//if l.cnf.LogicalBackup.DefaultsFile != "" {
51+
// buffer.WriteString(" --defaults-file " + l.cnf.LogicalBackup.DefaultsFile)
52+
//}
53+
//buffer.WriteString(" --trx-consistency-only")
54+
//buffer.WriteString(" --long-query-retries " + cast.ToString(l.cnf.LogicalBackup.FlushRetryCount))
55+
//buffer.WriteString(" --set-names " + l.cnf.Public.MysqlCharset)
56+
//buffer.WriteString(" --chunk-filesize " + cast.ToString(l.cnf.LogicalBackup.ChunkFileSize))
57+
//buffer.WriteString(" --long-query-retry-interval 10")
58+
// -- buffer.WriteString(" --checksum-all")
59+
//if l.cnf.LogicalBackup.Regex != "" {
60+
// buffer.WriteString(fmt.Sprintf(` -x '%s'`, l.cnf.LogicalBackup.Regex))
61+
//}
62+
//if common.BackupSchema && !common.BackupData { // backup schema only
63+
// buffer.WriteString(" --no-data")
64+
// buffer.WriteString(" --events --routines --triggers")
65+
//} else if !common.BackupSchema && common.BackupData { // backup data only
66+
// buffer.WriteString(" --no-schemas --no-views")
67+
//} else if common.BackupSchema && common.BackupData { // all
68+
// buffer.WriteString(" --events --routines --triggers")
69+
//}
70+
//buffer.WriteString(" --threads " + strconv.Itoa(l.cnf.LogicalBackup.Threads))
71+
// buffer.WriteString(" " + l.cnf.LogicalBackup.ExtraOpt)
72+
// buffer.WriteString(" > logs/mydumper_`date +%w`.log 2>&1")
73+
//
74+
// cmdStr := buffer.String()
75+
// logger.Log.Info(fmt.Sprintf("build backup cmd_line: %s", cmdStr))
76+
// return cmdStr, nil
77+
//}
78+
79+
//// Execute Execute logical dump command
80+
//func (l *LogicalDumper) Execute(enableTimeOut bool) error {
81+
// cmdStr, err := l.CreateDumpCmd()
82+
// if err != nil {
83+
// logger.Log.Error("Failed to create the cmd_line of dumping backup, error: ", err)
84+
// return err
85+
// }
86+
//
87+
// if enableTimeOut {
88+
// timeDiffUnix, err := GetMaxRunningTime(l.cnf.Public.BackupTimeOut)
89+
// if err != nil {
90+
// return err
91+
// }
92+
// ctx, cancel := context.WithTimeout(context.Background(), (time.Duration(timeDiffUnix))*time.Second)
93+
// defer cancel()
94+
//
95+
// // execute command with timeout
96+
// res, exeErr := exec.CommandContext(ctx, "/bin/bash", "-c", cmdStr).CombinedOutput()
97+
// logger.Log.Info("execute dumping logical backup with timeout, result:", string(res))
98+
// if exeErr != nil {
99+
// logger.Log.Error("Failed to execute dumping logical backup, error:", exeErr)
100+
// return exeErr
101+
// }
102+
// } else {
103+
// res, exeErr := exec.Command("/bin/bash", "-c", cmdStr).CombinedOutput()
104+
// logger.Log.Info("execute dumping logical backup without timeout, result:", string(res))
105+
// if exeErr != nil {
106+
// logger.Log.Error("Failed to execute dumping logical backup, error:", exeErr)
107+
// return exeErr
108+
// }
109+
// }
110+
// return nil
111+
//}
112+
37113
// Execute excute dumping backup with logical backup tool
38114
func (l *LogicalDumper) Execute(enableTimeOut bool) error {
39115
binPath := filepath.Join(l.dbbackupHome, "/bin/mydumper")

0 commit comments

Comments
 (0)