A fix for backups umounting too early

This commit is contained in:
Marcel Otte 2022-10-10 22:55:20 +02:00
parent 8376d00973
commit 0e98dc93e9
5 changed files with 19 additions and 30 deletions

View File

@ -93,6 +93,7 @@ func (b *Backup) PrepareRun() error {
// Run runs the backup script with appropriate rights. // Run runs the backup script with appropriate rights.
func (b *Backup) Run() error { func (b *Backup) Run() error {
log.Printf("Running backup '%s'.", b.Name) log.Printf("Running backup '%s'.", b.Name)
UiHdl.DisplayMessage("Backive backup", fmt.Sprintf("Running backup '%s'...", b.Name), MsgLevels.Info)
dev, ok := config.Devices[b.TargetDevice] dev, ok := config.Devices[b.TargetDevice]
if ok { if ok {
log.Printf("Device found: %s (%s).", dev.Name, dev.UUID) log.Printf("Device found: %s (%s).", dev.Name, dev.UUID)
@ -157,6 +158,7 @@ func (b *Backup) Run() error {
return err return err
} }
runs.RegisterRun(b) runs.RegisterRun(b)
UiHdl.DisplayMessage("Backive backup", fmt.Sprintf("Finished backup '%s'", b.Name), MsgLevels.Info)
return nil return nil
} }
// quit with error that the device is not available. // quit with error that the device is not available.

View File

@ -74,11 +74,15 @@ func defaultCallback(envMap map[string]string) {
if rerr != nil { if rerr != nil {
log.Printf("Error running the backup routine: %v", err) log.Printf("Error running the backup routine: %v", err)
} }
dev.Unmount()
} else { } else {
log.Printf("Backup '%s' can not run (error or frequency not reached): %s", backup.Name, err) msg := fmt.Sprintf("Backup '%s' can not run (error or frequency not reached): %s", backup.Name, err)
log.Printf(msg)
backive.UiHdl.DisplayMessage("Backive backup", msg, backive.MsgLevels.Info)
} }
} }
if dev.IsMounted() {
dev.Unmount()
}
} else { } else {
log.Println("No backup found.") log.Println("No backup found.")
} }

View File

@ -53,7 +53,6 @@ func (eh *EventHandler) RegisterCallback(cb func(map[string]string)) {
func (eh *EventHandler) process() { func (eh *EventHandler) process() {
client, err := mockAccept(eh) client, err := mockAccept(eh)
log.Println("Accepted client") log.Println("Accepted client")
UiHdl.DisplayMessage("Event debugging", "Catched event...", MsgLevels.Debug)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
return return
@ -87,7 +86,6 @@ func (eh *EventHandler) process() {
for k, v := range message["data"].(map[string]interface{}) { for k, v := range message["data"].(map[string]interface{}) {
env[k] = v.(string) env[k] = v.(string)
} }
UiHdl.DisplayMessage("Event debugging", "Got udev event msg.", MsgLevels.Debug)
} }
for _, v := range eh.callbacks { for _, v := range eh.callbacks {
if v != nil { if v != nil {

View File

@ -3,8 +3,6 @@ package ui
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"io"
"log" "log"
"net" "net"
"os" "os"
@ -59,10 +57,7 @@ func PollConnection() {
if c == nil { if c == nil {
log.Println("Creating connection") log.Println("Creating connection")
c, err = net.Dial("unix", config.Settings.UIUnixSocketLocation) c, err = net.Dial("unix", config.Settings.UIUnixSocketLocation)
} else { } // else already connected
err = fmt.Errorf("Connection already established")
log.Println(err)
}
// handle error on connection // handle error on connection
if err != nil { if err != nil {
log.Println(err) log.Println(err)
@ -75,24 +70,12 @@ func PollConnection() {
// receive msgs // receive msgs
if c != nil { if c != nil {
data := make([]byte, 2048) data := make([]byte, 2048)
for { nr, err := c.Read(data)
buf := make([]byte, 512)
nr, err := c.Read(buf)
log.Printf("Read %d bytes...", nr) log.Printf("Read %d bytes...", nr)
if err == io.ErrClosedPipe { if err != nil {
c = nil
err = nil
break
}
if err != nil && err != io.EOF {
log.Println(err) log.Println(err)
break break
} }
data = append(data, buf[0:nr]...)
if err == io.EOF {
break
}
}
sdata := string(bytes.Trim(data, "\x00")) sdata := string(bytes.Trim(data, "\x00"))
var message map[string]string var message map[string]string
log.Printf("Reading JSON: %s", sdata) log.Printf("Reading JSON: %s", sdata)
@ -124,7 +107,7 @@ func ShallShow(data map[string]string) bool {
if err != nil { if err != nil {
return false return false
} }
if level <= 10 { if level <= 30 {
return true return true
} }
if int(level) <= uisettings.globalLevel && messageLevel > 0 { if int(level) <= uisettings.globalLevel && messageLevel > 0 {

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"log" "log"
"net" "net"
"os"
"path" "path"
) )
@ -49,6 +50,7 @@ func (uh *UIHandler) Init(socketPath string) error {
dir, _ := path.Split(socketPath) dir, _ := path.Split(socketPath)
CreateDirectoryIfNotExists(dir) CreateDirectoryIfNotExists(dir)
uh.ls, err = net.Listen("unix", socketPath) uh.ls, err = net.Listen("unix", socketPath)
os.Chmod(socketPath, 0777)
if err != nil { if err != nil {
log.Printf("Error: %s", err) log.Printf("Error: %s", err)
return err return err
@ -79,8 +81,8 @@ func (uh *UIHandler) Listen() {
// DisplayMessage is the method to use inside the service to display messages, with intended level // DisplayMessage is the method to use inside the service to display messages, with intended level
func (uh *UIHandler) DisplayMessage(header string, message string, level MsgLevel) error { func (uh *UIHandler) DisplayMessage(header string, message string, level MsgLevel) error {
if uh.client != nil { if uh.client != nil {
var data map[string]interface{} var data = make(map[string]string)
data["level"] = int(level) data["level"] = fmt.Sprint(level)
data["header"] = header data["header"] = header
data["message"] = message data["message"] = message
b, err := json.Marshal(data) b, err := json.Marshal(data)