重构数据库备份与恢复模块 (#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

@@ -1,6 +1,7 @@
package entity
import (
"errors"
"mayfly-go/internal/common/utils"
"mayfly-go/pkg/model"
)
@@ -16,7 +17,7 @@ type AuthCert struct {
Remark string `json:"remark"`
}
func (a *AuthCert) TableName() string {
func (ac *AuthCert) TableName() string {
return "t_auth_cert"
}
@@ -28,14 +29,32 @@ const (
AuthCertTypePublic int8 = 2
)
// 密码加密
func (ac *AuthCert) PwdEncrypt() {
ac.Password = utils.PwdAesEncrypt(ac.Password)
ac.Passphrase = utils.PwdAesEncrypt(ac.Passphrase)
// PwdEncrypt 密码加密
func (ac *AuthCert) PwdEncrypt() error {
password, err := utils.PwdAesEncrypt(ac.Password)
if err != nil {
return errors.New("加密授权凭证密码失败")
}
passphrase, err := utils.PwdAesEncrypt(ac.Passphrase)
if err != nil {
return errors.New("加密授权凭证私钥失败")
}
ac.Password = password
ac.Passphrase = passphrase
return nil
}
// 密码解密
func (ac *AuthCert) PwdDecrypt() {
ac.Password = utils.PwdAesDecrypt(ac.Password)
ac.Passphrase = utils.PwdAesDecrypt(ac.Passphrase)
// PwdDecrypt 密码解密
func (ac *AuthCert) PwdDecrypt() error {
password, err := utils.PwdAesDecrypt(ac.Password)
if err != nil {
return errors.New("解密授权凭证密码失败")
}
passphrase, err := utils.PwdAesDecrypt(ac.Passphrase)
if err != nil {
return errors.New("解密授权凭证私钥失败")
}
ac.Password = password
ac.Passphrase = passphrase
return nil
}

View File

@@ -1,6 +1,7 @@
package entity
import (
"errors"
"mayfly-go/internal/common/utils"
"mayfly-go/pkg/model"
)
@@ -26,14 +27,24 @@ const (
MachineStatusDisable int8 = -1 // 禁用状态
)
func (m *Machine) PwdEncrypt() {
func (m *Machine) PwdEncrypt() error {
// 密码替换为加密后的密码
m.Password = utils.PwdAesEncrypt(m.Password)
password, err := utils.PwdAesEncrypt(m.Password)
if err != nil {
return errors.New("加密主机密码失败")
}
m.Password = password
return nil
}
func (m *Machine) PwdDecrypt() {
func (m *Machine) PwdDecrypt() error {
// 密码替换为解密后的密码
m.Password = utils.PwdAesDecrypt(m.Password)
password, err := utils.PwdAesDecrypt(m.Password)
if err != nil {
return errors.New("解密主机密码失败")
}
m.Password = password
return nil
}
func (m *Machine) UseAuthCert() bool {