Merge branch 'main' of http://192.168.0.229:3180/OMC/ems_backend
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"ems.agt/lib/core/conf"
|
||||||
"ems.agt/lib/dborm"
|
"ems.agt/lib/dborm"
|
||||||
"ems.agt/lib/log"
|
"ems.agt/lib/log"
|
||||||
"ems.agt/lib/services"
|
"ems.agt/lib/services"
|
||||||
@@ -20,20 +21,27 @@ import (
|
|||||||
var (
|
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
|
// DbBackup 系统备份-数据库备份1
|
||||||
func DbBackup(w http.ResponseWriter, r *http.Request) {
|
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文件路径
|
// 备份SQL文件路径
|
||||||
fileName := "database_backup_" + time.Now().Format("20060102150405") + ".sql"
|
fileName := "database_backup_" + time.Now().Format("20060102150405") + ".sql"
|
||||||
backupFile := dbConfig.Backup + "/" + fileName
|
backupFile := dbConfigBackup + "/" + fileName
|
||||||
|
|
||||||
// 执行mysqldump命令进行备份
|
// 执行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()
|
err := cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
services.ResponseErrorWithJson(w, 400, err.Error())
|
services.ResponseErrorWithJson(w, 400, err.Error())
|
||||||
@@ -52,12 +60,12 @@ func DbBackup(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// 系统备份-文件备份0
|
// 系统备份-文件备份0
|
||||||
func ConfBackup(w http.ResponseWriter, r *http.Request) {
|
func ConfBackup(w http.ResponseWriter, r *http.Request) {
|
||||||
dbConfig := config.GetYamlConfig().Database
|
dbConfigBackup := conf.Get("database.backup").(string)
|
||||||
etcDir := config.GetYamlConfig().NE.EtcDir
|
etcDir := conf.Get("ne.omcdir").(string)
|
||||||
|
|
||||||
// 文件名
|
// 文件名
|
||||||
fileName := "conf_backup_" + time.Now().Format("20060102150405") + ".tar.gz"
|
fileName := "conf_backup_" + time.Now().Format("20060102150405") + ".tar.gz"
|
||||||
backupFile := dbConfig.Backup + "/" + fileName
|
backupFile := dbConfigBackup + "/" + fileName
|
||||||
|
|
||||||
err := createTarGz(etcDir, backupFile)
|
err := createTarGz(etcDir, backupFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -53,8 +53,12 @@ var (
|
|||||||
|
|
||||||
// 查询数据库连接情况
|
// 查询数据库连接情况
|
||||||
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
|
var xormResponse XormResponse
|
||||||
|
|||||||
@@ -265,7 +265,15 @@ func init() {
|
|||||||
|
|
||||||
// 数据库连接情况
|
// 数据库连接情况
|
||||||
Register("GET", dbrest.UriDbConnection, dbrest.DbConnection, nil)
|
Register("GET", dbrest.UriDbConnection, dbrest.DbConnection, nil)
|
||||||
|
Register("GET", dbrest.CustomUriDbConnection, dbrest.DbConnection, nil)
|
||||||
Register("POST", dbrest.UriDbStop, dbrest.DbStop, 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)
|
Register("POST", lm.ExtBackupDataUri, lm.ExtDatabaseBackupData, nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user