-
Notifications
You must be signed in to change notification settings - Fork 1
/
actionOPN.go
82 lines (71 loc) · 2.23 KB
/
actionOPN.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package opnborg
import (
"crypto/sha256"
"sync"
"time"
)
// actionOPN, perform individual server backup
func actionOPN(server, tag string, config *OPNCall, id int, wg *sync.WaitGroup) {
// setup
defer wg.Done()
var err error
if config.Debug {
displayChan <- []byte("[BACKUP][START][SERVER] " + server)
}
// timestamp
ts := time.Now()
// get current opn config via xml
fetchFail, degraded, notice := false, false, ""
opn := new(Opnsense)
if config.Sync.Enable || config.RSysLog.Enable {
if opn, err = fetchOPN(server, config); err != nil {
displayChan <- []byte("[XML][FAIL]" + err.Error())
degraded = true
fetchFail = true
}
}
// check for pending BorgSYNC Orchestrator Tasks
if config.Sync.validConf && server != config.Sync.Master && !fetchFail {
if err = checkInstallPKG(server, config, opn); err != nil {
displayChan <- []byte("[SYNC][PKG][FAIL]" + err.Error())
degraded = true
}
}
// check for pending BorgOPS Operations Tasks
if config.RSysLog.Enable && !fetchFail {
if err = checkRSysLogConfig(server, config, opn); err != nil {
notice = "[RSYSLOG][CLIENT-CONF][FAIL]" + err.Error()
displayChan <- []byte(notice)
degraded = true
}
}
// fetch current XML backup from server
serverXML, err := fetchXML(server, config)
if err != nil {
displayChan <- []byte("[BACKUP][ERROR][FAIL:UNABLE-TO-FETCH-XML] " + server + err.Error())
setOPNStatus(config, server, tag, id, ts, notice, degraded, false)
return
}
// check for changes
sum := sha256.Sum256(serverXML)
last := lastSum(config, server)
if sum == last {
if config.Debug {
displayChan <- []byte("[BACKUP][SERVER][NO-CHANGE] " + server)
}
setOPNStatus(config, server, tag, id, ts, notice, degraded, true)
return
}
// set git global (atomic) worktree state tracker
if config.Git {
config.dirty.Store(true)
}
// check xml file into storage
if err = checkIntoStore(config, server, "xml", serverXML, ts, sum); err != nil {
displayChan <- []byte("[BACKUP][ERROR][FAIL:XML-STORE-CHECKIN] " + err.Error())
setOPNStatus(config, server, tag, id, ts, notice, degraded, false)
return
}
displayChan <- []byte("[BACKUP][OK][SUCCESS:XML-STORE-CHECKIN-OF-MODIFIED-XML]")
setOPNStatus(config, server, tag, id, ts, notice, degraded, true)
}