forked from gobackup/gobackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
64 lines (54 loc) · 1.28 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"github.com/huacnlee/gobackup/archive"
"github.com/huacnlee/gobackup/compressor"
"github.com/huacnlee/gobackup/config"
"github.com/huacnlee/gobackup/database"
"github.com/huacnlee/gobackup/encryptor"
"github.com/huacnlee/gobackup/helper"
"github.com/huacnlee/gobackup/logger"
"github.com/huacnlee/gobackup/storage"
)
// Model class
type Model struct {
Config config.ModelConfig
}
// Perform model
func (ctx Model) perform() {
logger.Info("======== " + ctx.Config.Name + " ========")
logger.Info("WorkDir:", ctx.Config.DumpPath+"\n")
defer ctx.cleanup()
err := database.Run(ctx.Config)
if err != nil {
logger.Error(err)
return
}
if ctx.Config.Archive != nil {
err = archive.Run(ctx.Config)
if err != nil {
logger.Error(err)
return
}
}
archivePath, err := compressor.Run(ctx.Config)
if err != nil {
logger.Error(err)
return
}
archivePath, err = encryptor.Run(archivePath, ctx.Config)
if err != nil {
logger.Error(err)
return
}
err = storage.Run(ctx.Config, archivePath)
if err != nil {
logger.Error(err)
return
}
}
// Cleanup model temp files
func (ctx Model) cleanup() {
logger.Info("Cleanup temp dir...\n")
helper.Exec("rm", "-rf", ctx.Config.DumpPath)
logger.Info("======= End " + ctx.Config.Name + " =======\n\n")
}