feat: 系统备份接口声明
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user