Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9e1d9fb
Start with ui dev, hello world.
qwc Mar 7, 2022
a738650
Creating the layout base
qwc Mar 7, 2022
01d7e36
filling ui, stuck at removing center content dynamically
qwc Mar 9, 2022
2c14479
Do not write code tired as hell...
qwc Mar 12, 2022
031374a
Show more stuff
qwc Mar 14, 2022
f8f9666
Update fyne and viper
qwc Mar 17, 2022
ce5a203
Playing with systray
qwc Mar 17, 2022
7c89e44
Fix fyne theme import
qwc Mar 17, 2022
59484e9
Using latest develop from fyne for proper systray menu
qwc Mar 21, 2022
2d798e5
Removed some useless logging
qwc Mar 21, 2022
449ae39
Add reoccuring notifications for initiation of backups
qwc Apr 4, 2022
f62c670
Minimalize the needed code, only notifications
qwc Apr 18, 2022
cfc37e5
Reworking UI concept...
qwc Jun 7, 2022
cade8cc
Parse message lvl and menu for setting it.
qwc Jun 8, 2022
728af0d
struct for saving and message level handling ...
qwc Jun 8, 2022
e987266
Added an overview architecture diagram
qwc Jul 4, 2022
62350fe
Make the code fit for using the unix socket and save settings
qwc Aug 14, 2022
17d379a
Add proper comments to ui_main
qwc Aug 14, 2022
f4a1272
Update to go 1.19
qwc Aug 14, 2022
9f8e992
Update fyne to release
qwc Aug 14, 2022
d9695b1
Work from fyne@develop again
qwc Aug 14, 2022
865511e
Update go.yml
qwc Aug 14, 2022
d38b12e
try to get the runner up to something
qwc Aug 14, 2022
fee1d2b
Update go.yml
qwc Aug 14, 2022
3b31b58
Update go.yml
qwc Aug 14, 2022
45f4f1d
Update go.yml
qwc Aug 14, 2022
41fb582
Update go.yml
qwc Aug 14, 2022
85defa8
Update go.yml
qwc Aug 14, 2022
a92cea4
Update go.yml
qwc Aug 14, 2022
b23fd55
Update go.yml
qwc Aug 14, 2022
b61e440
Update go.yml
qwc Aug 14, 2022
a242ceb
Update go.yml
qwc Aug 14, 2022
fe8f26e
Update go.yml
qwc Aug 14, 2022
8376d00
Try abstract unix sockets, failing atm...
qwc Sep 2, 2022
0e98dc9
A fix for backups umounting too early
qwc Oct 10, 2022
559e7f7
Fix retrying ui connection
qwc Oct 10, 2022
a78b11a
Fix problem of run database
qwc Mar 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/go-release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Go

on:
on:
release

jobs:
Expand All @@ -13,7 +13,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.19
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2.7.0
with:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: setup runner
run: |
# sudo apt search xorg
sudo apt-get install -y xserver-xorg libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libglvnd-dev libxxf86vm-dev

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.19
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2.7.0
with:
Expand Down
3 changes: 2 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ builds:
id: "backive_ui"
binary: backive_ui
env:
- CGO_ENABLED=0
- CGO_ENABLED=1
- GOOS=linux
goarch:
- amd64
goos:
Expand Down
1 change: 1 addition & 0 deletions backive-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ backups:
settings:
systemMountPoint: /mnt/backups
unixSocketLocation: /var/local/backive/backive.sock
uiUnixSocketLocation: /var/local/backive/ui.sock
logLocation: /var/log/backive
dbLocation: /var/lib/backive

Expand Down
121 changes: 121 additions & 0 deletions backive.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
@startuml
namespace backive {
class Backup << (S,Aquamarine) >> {
- logger *log.Logger

+ Name string
+ TargetDevice string
+ TargetPath string
+ SourcePath string
+ ScriptPath <font color=blue>interface</font>{}
+ Frequency int
+ ExeUser string
+ Label string

+ CanRun() error
+ PrepareRun() error
+ Run() error
+ ShouldRun() bool

}
class Backups << (S,Aquamarine) >> {
+ FindBackupsForDevice(d Device) ([]*Backup, bool)

}
class Configuration << (S,Aquamarine) >> {
+ Settings Settings
+ Devices Devices
+ Backups Backups
+ Vconfig *viper.Viper

+ CreateViper()
+ Load()

}
class Database << (S,Aquamarine) >> {
- data <font color=blue>map</font>[string]<font color=blue>interface</font>{}

+ Save()
+ Load()

}
class Device << (S,Aquamarine) >> {
- isMounted bool

+ Name string
+ UUID string
+ OwnerUser string

+ Mount() error
+ Unmount() error
+ IsMounted() bool

}
class EventHandler << (S,Aquamarine) >> {
- ls net.Listener
- callbacks []<font color=blue>func</font>(<font color=blue>map</font>[string]string)

- process()

+ Init(socketPath string) error
+ Listen()
+ RegisterCallback(cb <font color=blue>func</font>(<font color=blue>map</font>[string]string) )

}
class MsgLvls << (S,Aquamarine) >> {
+ Error MsgLevel
+ Finish MsgLevel
+ Remind MsgLevel
+ Info MsgLevel
+ Debug MsgLevel

}
class Runs << (S,Aquamarine) >> {
- data <font color=blue>map</font>[string][]time.Time

+ Load(db Database)
+ Save(db Database)
+ RegisterRun(b *Backup)
+ LastRun(b *Backup) (time.Time, error)

}
class Settings << (S,Aquamarine) >> {
+ SystemMountPoint string
+ UserMountPoint string
+ UnixSocketLocation string
+ UIUnixSocketLocation string
+ LogLocation string
+ DbLocation string

}
class UIHandler << (S,Aquamarine) >> {
- ls net.Listener
- client net.Conn

+ Init(socketPath string) error
+ Listen()
+ DisplayMessage(header string, message string, level MsgLevel) error

}
class backive.Backups << (T, #FF7700) >> {
}
class backive.Devices << (T, #FF7700) >> {
}
class backive.MsgLevel << (T, #FF7700) >> {
}
}


namespace ui {
class uiSettings << (S,Aquamarine) >> {
- hideUntil time.Time
- globalLevel int

}
}


"__builtin__.int" #.. "backive.MsgLevel"
"backive.<font color=blue>map</font>[string]*Backup" #.. "backive.Backups"
"backive.<font color=blue>map</font>[string]*Device" #.. "backive.Devices"
@enduml
58 changes: 46 additions & 12 deletions backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (b *Backup) PrepareRun() error {
// Run runs the backup script with appropriate rights.
func (b *Backup) Run() error {
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]
if ok {
log.Printf("Device found: %s (%s).", dev.Name, dev.UUID)
Expand All @@ -102,15 +103,14 @@ func (b *Backup) Run() error {
}
if ok && dev.IsMounted() {
var scriptWArgs []string
// ScriptPath may be an slice/array of a script path with parameters or just a string with a script path
switch slice := b.ScriptPath.(type) {
case []interface{}:
for _, v := range slice {
scriptWArgs = append(scriptWArgs, v.(string))
}
case []string:
for _, v := range slice {
scriptWArgs = append(scriptWArgs, v)
}
scriptWArgs = append(scriptWArgs, slice...)
case string:
scriptWArgs = append(scriptWArgs, slice)
default:
Expand Down Expand Up @@ -156,6 +156,7 @@ func (b *Backup) Run() error {
return err
}
runs.RegisterRun(b)
UiHdl.DisplayMessage("Backive backup", fmt.Sprintf("Finished backup '%s'", b.Name), MsgLevels.Info)
return nil
}
// quit with error that the device is not available.
Expand All @@ -170,24 +171,53 @@ type Runs struct {
// Load loads the data from the json database
func (r *Runs) Load(db Database) {
data := db.data["runs"]
if data != "" {
runerr := json.Unmarshal([]byte(db.data["runs"]), &r.data)
if runerr != nil {
panic(runerr)
if data != nil {
log.Println("Loading runs db")
switch d := data.(type) {
case string:
// be able to read the old version
log.Println("Loading legacy data")
runerr := json.Unmarshal([]byte(data.(string)), &r.data)
if runerr != nil {
panic(runerr)
}
case map[string]interface{}:
log.Println("Loading data")
if r.data == nil {
r.data = make(map[string][]time.Time)
}
raw := data.(map[string]interface{})
for k, v := range raw {
r.data[k] = make([]time.Time, 0)
for _, i := range v.([]interface{}) {
t, _ := time.Parse(time.RFC3339Nano, i.(string))
r.data[k] = append(r.data[k], t)
}
}
LogToJson(data)
default:
log.Printf("got data type: %s", d)
}
}
log.Println("Data loaded:")
LogToJson(r.data)
}

// Save saves the data into the json database
func (r *Runs) Save(db Database) {
if db.data == nil {
db.data = map[string]string{}
db.data = map[string]interface{}{}
}
str, err := json.Marshal(r.data)
db.data["runs"] = r.data
LogToJson(db.data)
}

func LogToJson(data interface{}) {
str, err := json.Marshal(data)
if err != nil {
panic(err)
}
db.data["runs"] = string(str)
log.Printf("Data: %s", str)
}

// ShouldRun Takes a backup key and returns a bool if a backup should run now.
Expand All @@ -205,17 +235,21 @@ func (b *Backup) ShouldRun() bool {
if freq == 0 {
return true
}
if ok != nil && lr.Equal(time.Unix(0, 0)) {
return true
}
return false
}

// RegisterRun saves a date of a backup run into the internal storage
func (r *Runs) RegisterRun(b *Backup) {
if r.data == nil {
r.data = map[string][]time.Time{}
x := map[string][]time.Time{}
r.data = x
}
nbl, ok := r.data[b.Name]
if !ok {
nbl = make([]time.Time, 1)
nbl = make([]time.Time, 0)
}
nbl = append([]time.Time{time.Now()}, nbl...)
r.data[b.Name] = nbl
Expand Down
2 changes: 2 additions & 0 deletions backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,5 @@ func TestRun(t *testing.T) {
return nil
}
}

// TODO: write a test for the lastRun method!
30 changes: 22 additions & 8 deletions cmd/backive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,19 @@ func defaultCallback(envMap map[string]string) {
log.Printf("Device: Name: %s, UUID: %s", dev.Name, dev.UUID)
backups, found := config.Backups.FindBackupsForDevice(*dev)
log.Println("Searching configured backups...")
bnames := make([]string, 0)
for _, v := range backups {
bnames = append(bnames, v.Name)
}
log.Printf("Found backups: %s", bnames)
if found {
// only mount device if we really have to do a backup!
dev.Mount()
log.Println("Device mounted.")
for _, backup := range backups {
log.Printf("Backup found: %s", backup.Name)
log.Printf("Backup running: %s", backup.Name)
err := backup.CanRun()
if err == nil {
// only mount device if we really have to do a backup!
dev.Mount()
log.Println("Device mounted.")
log.Println("Backup is able to run (config check passed).")
prepErr := backup.PrepareRun()
log.Println("Prepared run.")
Expand All @@ -74,11 +79,15 @@ func defaultCallback(envMap map[string]string) {
if rerr != nil {
log.Printf("Error running the backup routine: %v", err)
}
dev.Unmount()
} 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 {
log.Println("No backup found.")
}
Expand Down Expand Up @@ -127,17 +136,22 @@ func main() {
if err != nil {
log.Printf("Removal of %s failed.", config.Settings.UnixSocketLocation)
}
err = os.Remove(config.Settings.UIUnixSocketLocation)
if err != nil {
log.Printf("Removal of %s failed.", config.Settings.UIUnixSocketLocation)
}
os.Exit(code)
}()

// TODO: do proper signal handling!
log.Println("backive starting up...")
// find and load config
database.Load()
config.Load()
setupLogging()
backive.Init(config, database)

backive.UiHdl.Init(config.Settings.UIUnixSocketLocation)
// Start UIHandler to be able to inform users through notifications
go backive.UiHdl.Listen()
// init scheduler and check for next needed runs?
// start event loop
events.Init(config.Settings.UnixSocketLocation)
Expand Down
Loading