mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
重构数据库备份与恢复模块 (#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:
@@ -1,25 +1,25 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"mayfly-go/internal/common/utils"
|
||||
"mayfly-go/internal/db/dbm"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type DbInstance struct {
|
||||
model.Model
|
||||
|
||||
Name string `orm:"column(name)" json:"name"`
|
||||
Type dbm.DbType `orm:"column(type)" json:"type"` // 类型,mysql oracle等
|
||||
Host string `orm:"column(host)" json:"host"`
|
||||
Port int `orm:"column(port)" json:"port"`
|
||||
Network string `orm:"column(network)" json:"network"`
|
||||
Username string `orm:"column(username)" json:"username"`
|
||||
Password string `orm:"column(password)" json:"-"`
|
||||
Params string `orm:"column(params)" json:"params"`
|
||||
Remark string `orm:"column(remark)" json:"remark"`
|
||||
SshTunnelMachineId int `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"` // 类型,mysql oracle等
|
||||
Host string `json:"host"`
|
||||
Port int `json:"port"`
|
||||
Network string `json:"network"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"-"`
|
||||
Params string `json:"params"`
|
||||
Remark string `json:"remark"`
|
||||
SshTunnelMachineId int `json:"sshTunnelMachineId"` // ssh隧道机器id
|
||||
}
|
||||
|
||||
func (d *DbInstance) TableName() string {
|
||||
@@ -39,12 +39,22 @@ func (d *DbInstance) GetNetwork() string {
|
||||
return fmt.Sprintf("%s+ssh:%d", d.Type, d.SshTunnelMachineId)
|
||||
}
|
||||
|
||||
func (d *DbInstance) PwdEncrypt() {
|
||||
func (d *DbInstance) PwdEncrypt() error {
|
||||
// 密码替换为加密后的密码
|
||||
d.Password = utils.PwdAesEncrypt(d.Password)
|
||||
password, err := utils.PwdAesEncrypt(d.Password)
|
||||
if err != nil {
|
||||
return errors.New("加密数据库密码失败")
|
||||
}
|
||||
d.Password = password
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DbInstance) PwdDecrypt() {
|
||||
func (d *DbInstance) PwdDecrypt() error {
|
||||
// 密码替换为解密后的密码
|
||||
d.Password = utils.PwdAesDecrypt(d.Password)
|
||||
password, err := utils.PwdAesDecrypt(d.Password)
|
||||
if err != nil {
|
||||
return errors.New("解密数据库密码失败")
|
||||
}
|
||||
d.Password = password
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user