重构数据库备份与恢复模块 (#80)

* fix: 保存 LastResult 时截断字符串过长部分,以避免数据库报错

* refactor: 新增 entity.DbTaskBase 和 persistence.dbTaskBase, 用于实现数据库备份和恢复任务处理相关部分

* fix: aeskey变更后,解密密码出现数组越界访问错误

* fix: 时间属性为零值时,保存到 mysql 数据库报错

* refactor db.infrastructure.service.scheduler

* feat: 实现立即备份功能

* refactor db.infrastructure.service.db_instance

* refactor: 从数据库中获取数据库备份目录、mysql文件路径等配置信息

* fix: 数据库备份和恢复问题

* fix: 修改 .gitignore 文件,忽略数据库备份目录和数据库程序目录
This commit is contained in:
kanzihuang
2024-01-05 08:55:34 +08:00
committed by GitHub
parent 76fd6675b5
commit ae3d2659aa
83 changed files with 1819 additions and 1688 deletions

View File

@@ -2,6 +2,8 @@ package config
import (
sysapp "mayfly-go/internal/sys/application"
"path/filepath"
"runtime"
)
const (
@@ -9,6 +11,7 @@ const (
ConfigKeyDbQueryMaxCount string = "DbQueryMaxCount" // 数据库查询的最大数量
ConfigKeyDbBackupRestore string = "DbBackupRestore" // 数据库备份
ConfigKeyDbMysqlBin string = "MysqlBin" // mysql可执行文件配置
ConfigKeyDbMariaDbBin string = "MariaDbBin" // mariadb可执行文件配置
)
// 获取数据库最大查询数量配置
@@ -36,7 +39,7 @@ func GetDbBackupRestore() *DbBackupRestore {
if backupPath == "" {
backupPath = "./db/backup"
}
dbrc.BackupPath = backupPath
dbrc.BackupPath = filepath.Join(backupPath)
return dbrc
}
@@ -50,35 +53,39 @@ type MysqlBin struct {
}
// 获取数据库备份配置
func GetMysqlBin() *MysqlBin {
c := sysapp.GetConfigApp().GetConfig(ConfigKeyDbMysqlBin)
func GetMysqlBin(configKey string) *MysqlBin {
c := sysapp.GetConfigApp().GetConfig(configKey)
jm := c.GetJsonMap()
mbc := new(MysqlBin)
path := jm["path"]
if path == "" {
path = "./db/backup"
path = "./db/mysql/bin"
}
mbc.Path = path
mbc.Path = filepath.Join(path)
var extName string
if runtime.GOOS == "windows" {
extName = ".exe"
}
mysqlPath := jm["mysql"]
if mysqlPath == "" {
mysqlPath = path + "mysql"
mysqlPath = filepath.Join(path, "mysql"+extName)
}
mbc.MysqlPath = mysqlPath
mbc.MysqlPath = filepath.Join(mysqlPath)
mysqldumpPath := jm["mysqldump"]
if mysqldumpPath == "" {
mysqldumpPath = path + "mysqldump"
mysqldumpPath = filepath.Join(path, "mysqldump"+extName)
}
mbc.MysqldumpPath = mysqldumpPath
mbc.MysqldumpPath = filepath.Join(mysqldumpPath)
mysqlbinlogPath := jm["mysqlbinlog"]
if mysqlbinlogPath == "" {
mysqlbinlogPath = path + "mysqlbinlog"
mysqlbinlogPath = filepath.Join(path, "mysqlbinlog"+extName)
}
mbc.MysqlbinlogPath = mysqlbinlogPath
mbc.MysqlbinlogPath = filepath.Join(mysqlbinlogPath)
return mbc
}