Browse Source

Revert "增加数据备份功能"

This reverts commit 281eb12715.
pull/2/head
娄文智 4 years ago
parent
commit
d3de71c590
9 changed files with 5 additions and 94 deletions
  1. +0
    -1
      .gitignore
  2. +2
    -4
      conf/app.go
  3. +0
    -2
      conf/db.go
  4. +0
    -37
      db/corn.go
  5. +0
    -32
      db/db.go
  6. +0
    -9
      db/db_test.go
  7. +0
    -1
      go.mod
  8. +0
    -3
      go.sum
  9. +3
    -5
      main.go

+ 0
- 1
.gitignore View File

@ -1 +0,0 @@
.idea/

+ 2
- 4
conf/app.go View File

@ -1,10 +1,8 @@
package conf package conf
var ExampleFile = "http://localhost:8092/public/uploadxlsx/example.xlsx"
//var ExampleFile = "http://localhost:22000/public/uploadxlsx/example.xlsx"
var ExampleFile = "http://localhost:22000/public/uploadxlsx/example.xlsx"
//var Baseurl = "http://localhost:22000"
var Baseurl = "http://localhost:8092"
var Baseurl = "http://localhost:22000"
type AppConf struct { type AppConf struct {
DisablePathCorrection bool DisablePathCorrection bool


+ 0
- 2
conf/db.go View File

@ -8,7 +8,6 @@ type DbConf struct {
User string User string
Pwd string Pwd string
DbName string DbName string
BackUp string
} }
//线上服务器配置 //线上服务器配置
@ -18,7 +17,6 @@ var MasterDbConfig DbConf = DbConf{
User: "root", User: "root",
Pwd: "Leit2020", Pwd: "Leit2020",
DbName: "lappserver", DbName: "lappserver",
BackUp: "C:\\lappServer\\dblog",
} }
//测试服务器配置 //测试服务器配置


+ 0
- 37
db/corn.go View File

@ -1,37 +0,0 @@
// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.
package db
import (
cron "github.com/robfig/cron/v3"
)
/******************************************************************************
*
* @Function Name :
*-----------------------------------------------------------------------------
*
* @Description : 定时任务
*
* @Function Parameters:
*
* @Return Value :
*
* @Author : Lou Wenzhi
*
* @Date : 2021/3/8 18:00
*
******************************************************************************/
func CornTime() {
crontab := cron.New()
task := func() {
BackUp()
}
// 添加定时任务, * * * * * 是 crontab,表示每分钟执行一次
//crontab.AddFunc("*/1 * * * *", task)
crontab.AddFunc("@midnight", task)
// 启动定时器
crontab.Start()
// 定时任务是另起协程执行的,这里使用 select 简答阻塞.实际开发中需要
// 根据实际情况进行控制
select {}
}

+ 0
- 32
db/db.go View File

@ -8,10 +8,7 @@ import (
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
"lapp_-wy/conf" "lapp_-wy/conf"
"lapp_-wy/utils"
"lapp_-wy/web/middleware/glog"
"log" "log"
"path/filepath"
"sync" "sync"
"time" "time"
) )
@ -76,32 +73,3 @@ func MgoDb() *mongo.Client {
return mgoDb return mgoDb
} }
} }
//数据备份
func BackUp() {
var (
engine *xorm.Engine
err error
)
c := conf.MasterDbConfig
driveSource := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8",
c.User, c.Pwd, c.Host, c.Port, c.DbName)
if engine, err = xorm.NewEngine(conf.DriverName, driveSource); err != nil {
return
}
if err = engine.Ping(); err != nil {
glog.ErrorExtln("数据库连接失败:", "err:", err.Error())
return
} else {
glog.ErrorExtln("数据库连接成功:", "driveSource", driveSource)
}
filename := utils.TimeFormat(time.Now(),"yyyy-MM-dd") + ".sql"
dirpath := filepath.Join(c.BackUp,filename)
err = engine.DumpAllToFile(dirpath, conf.DriverName)
if err != nil {
return
}
}

+ 0
- 9
db/db_test.go View File

@ -11,7 +11,6 @@ import (
"log" "log"
"path/filepath" "path/filepath"
"testing" "testing"
"time"
) )
func TestDb(t *testing.T) { func TestDb(t *testing.T) {
@ -29,14 +28,6 @@ func TestDb(t *testing.T) {
t.Error(err) t.Error(err)
return return
} }
filename := utils.TimeFormat(time.Now(),"yyyy-MM-dd") + ".sql"
dirpath := filepath.Join(c.BackUp,filename)
fmt.Println(dirpath)
err = engine.DumpAllToFile(dirpath, conf.DriverName)
if err != nil{
log.Println("数据库导出失败:", err.Error())
return
}
//开启sql,debug //开启sql,debug
engine.ShowSQL(true) engine.ShowSQL(true)
if err = engine.Ping(); err != nil { if err = engine.Ping(); err != nil {


+ 0
- 1
go.mod View File

@ -33,7 +33,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/moul/http2curl v1.0.0 // indirect github.com/moul/http2curl v1.0.0 // indirect
github.com/robfig/cron/v3 v3.0.1
github.com/sergi/go-diff v1.1.0 // indirect github.com/sergi/go-diff v1.1.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect github.com/smartystreets/goconvey v1.6.4 // indirect


+ 0
- 3
go.sum View File

@ -352,9 +352,6 @@ github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=


+ 3
- 5
main.go View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"github.com/kardianos/service" "github.com/kardianos/service"
"github.com/kataras/iris" "github.com/kataras/iris"
"lapp_-wy/db"
"lapp_-wy/inits/parse" "lapp_-wy/inits/parse"
"lapp_-wy/utils" "lapp_-wy/utils"
"lapp_-wy/web/middleware/glog" "lapp_-wy/web/middleware/glog"
@ -104,10 +103,9 @@ func imain() {
app.RegisterView(iris.HTML(savePath, ".html")) app.RegisterView(iris.HTML(savePath, ".html"))
// 设置静态资源 // 设置静态资源
app.StaticWeb("/public", savePath) app.StaticWeb("/public", savePath)
//数据备份
go db.CornTime()
//启动监听端口 //启动监听端口
//app.Run(iris.Addr(":22000"), iris.WithConfiguration(parse.C))
app.Run(iris.Addr(":8092"), iris.WithConfiguration(parse.C))
app.Run(iris.Addr(":22000"), iris.WithConfiguration(parse.C))
//app.Run(iris.Addr(":8092"), iris.WithConfiguration(parse.C))
} }

Loading…
Cancel
Save