From e2ecd484858456c0afc8fee34fb481fc641c4ffa Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 5 Sep 2023 14:11:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=B3=BB=E7=BB=9F=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- features/dbrest/backup.go | 24 ++++++++++++++++-------- features/dbrest/dbrest.go | 8 ++++++-- lib/routes/routes.go | 8 ++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/features/dbrest/backup.go b/features/dbrest/backup.go index 007ec236..f8cfb05a 100644 --- a/features/dbrest/backup.go +++ b/features/dbrest/backup.go @@ -10,6 +10,7 @@ import ( "path/filepath" "time" + "ems.agt/lib/core/conf" "ems.agt/lib/dborm" "ems.agt/lib/log" "ems.agt/lib/services" @@ -19,21 +20,28 @@ import ( var ( // 系统备份-数据库备份 - UriDbBackup = config.DefaultUriPrefix + "/dataManagement/{apiVersion}/dbBackup" + UriDbBackup = config.DefaultUriPrefix + "/dataManagement/{apiVersion}/dbBackup" + CustomUriDbBackup = config.UriPrefix + "/dataManagement/{apiVersion}/dbBackup" // for external + // 系统备份-文件备份 - UriConfBackup = config.DefaultUriPrefix + "/dataManagement/{apiVersion}/confBackup" + UriConfBackup = config.DefaultUriPrefix + "/dataManagement/{apiVersion}/confBackup" + CustomUriConfBackup = config.UriPrefix + "/dataManagement/{apiVersion}/confBackup" // for external + ) // DbBackup 系统备份-数据库备份1 func DbBackup(w http.ResponseWriter, r *http.Request) { - dbConfig := config.GetYamlConfig().Database + dbConfigHost := conf.Get("database.host").(string) + dbConfigUser := conf.Get("database.user").(string) + dbConfigPassword := conf.Get("database.password").(string) + dbConfigBackup := conf.Get("database.backup").(string) // 备份SQL文件路径 fileName := "database_backup_" + time.Now().Format("20060102150405") + ".sql" - backupFile := dbConfig.Backup + "/" + fileName + backupFile := dbConfigBackup + "/" + fileName // 执行mysqldump命令进行备份 - cmd := exec.Command("mysqldump", "-u", dbConfig.User, "-p"+dbConfig.Password, "-h", dbConfig.Host, "--all-databases", ">", backupFile) + cmd := exec.Command("mysqldump", "-u", dbConfigUser, "-p"+dbConfigPassword, "-h", dbConfigHost, "--all-databases", ">", backupFile) err := cmd.Start() if err != nil { services.ResponseErrorWithJson(w, 400, err.Error()) @@ -52,12 +60,12 @@ func DbBackup(w http.ResponseWriter, r *http.Request) { // 系统备份-文件备份0 func ConfBackup(w http.ResponseWriter, r *http.Request) { - dbConfig := config.GetYamlConfig().Database - etcDir := config.GetYamlConfig().NE.EtcDir + dbConfigBackup := conf.Get("database.backup").(string) + etcDir := conf.Get("ne.omcdir").(string) // 文件名 fileName := "conf_backup_" + time.Now().Format("20060102150405") + ".tar.gz" - backupFile := dbConfig.Backup + "/" + fileName + backupFile := dbConfigBackup + "/" + fileName err := createTarGz(etcDir, backupFile) if err != nil { diff --git a/features/dbrest/dbrest.go b/features/dbrest/dbrest.go index d3d74fc6..b93d9054 100644 --- a/features/dbrest/dbrest.go +++ b/features/dbrest/dbrest.go @@ -52,9 +52,13 @@ var ( CustomXormDataSQLUri = config.UriPrefix + "/dataManagement/{apiVersion}/{elementTypeValue}/{objectTypeValue}" // for external // 查询数据库连接情况 - UriDbConnection = config.DefaultUriPrefix + "/dataManagement/{apiVersion}/dbConnection" + UriDbConnection = config.DefaultUriPrefix + "/dataManagement/{apiVersion}/dbConnection" + CustomUriDbConnection = config.UriPrefix + "/dataManagement/{apiVersion}/dbConnection" // for external + // 终结非法的数据库连接 - UriDbStop = config.DefaultUriPrefix + "/dataManagement/{apiVersion}/dbStop" + UriDbStop = config.DefaultUriPrefix + "/dataManagement/{apiVersion}/dbStop" + CustomUriDbStop = config.UriPrefix + "/dataManagement/{apiVersion}/dbStop" // for external + ) var xormResponse XormResponse diff --git a/lib/routes/routes.go b/lib/routes/routes.go index 387b9500..79307471 100644 --- a/lib/routes/routes.go +++ b/lib/routes/routes.go @@ -265,7 +265,15 @@ func init() { // 数据库连接情况 Register("GET", dbrest.UriDbConnection, dbrest.DbConnection, nil) + Register("GET", dbrest.CustomUriDbConnection, dbrest.DbConnection, nil) Register("POST", dbrest.UriDbStop, dbrest.DbStop, nil) + Register("POST", dbrest.CustomUriDbStop, dbrest.DbStop, nil) + + // 系统备份 + Register("POST", dbrest.UriDbBackup, dbrest.DbBackup, nil) + Register("POST", dbrest.CustomUriDbBackup, dbrest.DbBackup, nil) + Register("POST", dbrest.UriConfBackup, dbrest.ConfBackup, nil) + Register("POST", dbrest.CustomUriConfBackup, dbrest.ConfBackup, nil) // 日志表备份 Register("POST", lm.ExtBackupDataUri, lm.ExtDatabaseBackupData, nil)