mirror of https://github.com/qwc/backive.git
Some restructuring to avoid import loops
This commit is contained in:
parent
5890e490d5
commit
627c6cc622
|
@ -9,6 +9,7 @@ before:
|
||||||
builds:
|
builds:
|
||||||
- main: ./cmd/backive/main.go
|
- main: ./cmd/backive/main.go
|
||||||
id: backive
|
id: backive
|
||||||
|
binary: backive
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
goarch:
|
goarch:
|
||||||
|
@ -19,6 +20,7 @@ builds:
|
||||||
# - darwin
|
# - darwin
|
||||||
- main: ./cmd/backive_udev/main.go
|
- main: ./cmd/backive_udev/main.go
|
||||||
id: backive_udev
|
id: backive_udev
|
||||||
|
binary: backive_udev
|
||||||
goarch:
|
goarch:
|
||||||
- amd64
|
- amd64
|
||||||
env:
|
env:
|
||||||
|
@ -29,6 +31,7 @@ builds:
|
||||||
# - darwin
|
# - darwin
|
||||||
- main: ./cmd/backive_ui/main.go
|
- main: ./cmd/backive_ui/main.go
|
||||||
id: backive_ui
|
id: backive_ui
|
||||||
|
binary: backive_ui
|
||||||
env:
|
env:
|
||||||
- CGO_ENABLED=0
|
- CGO_ENABLED=0
|
||||||
goarch:
|
goarch:
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package backup
|
||||||
|
|
||||||
|
// Backup contains all necessary information for executing a configured backup.
|
||||||
|
type Backup struct {
|
||||||
|
Name string `mapstructure:",omitempty"`
|
||||||
|
TargetDevice string `mapstructure:"targetDevice"`
|
||||||
|
TargetDir string `mapstructure:"targetDir"`
|
||||||
|
SourceDir string `mapstructure:"sourceDir"`
|
||||||
|
ScriptPath string `mapstructure:"scriptPath"`
|
||||||
|
Frequency int `mapstructure:"frequency"`
|
||||||
|
ExeUser string `mapstructure:"user,omitempty"`
|
||||||
|
}
|
|
@ -3,7 +3,8 @@ package config
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/qwc/backive/core"
|
"github.com/qwc/backive/backup"
|
||||||
|
"github.com/qwc/backive/device"
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@ -27,10 +28,10 @@ type Settings struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devices is nothing else than a name to Device type mapping
|
// Devices is nothing else than a name to Device type mapping
|
||||||
type Devices map[string]core.Device
|
type Devices map[string]device.Device
|
||||||
|
|
||||||
// Backups is nothing else than a name to Backup type mapping
|
// Backups is nothing else than a name to Backup type mapping
|
||||||
type Backups map[string]core.Backup
|
type Backups map[string]backup.Backup
|
||||||
|
|
||||||
// CreateViper creates a viper instance for usage later
|
// CreateViper creates a viper instance for usage later
|
||||||
func CreateViper() *viper.Viper {
|
func CreateViper() *viper.Viper {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package core
|
package device
|
||||||
|
|
||||||
// Device represents a device, with a name easy to remember and the UUID to identify it, optionally an owner.
|
// Device represents a device, with a name easy to remember and the UUID to identify it, optionally an owner.
|
||||||
type Device struct {
|
type Device struct {
|
|
@ -1,27 +1,17 @@
|
||||||
package core
|
package runner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/qwc/backive/backup"
|
||||||
"github.com/qwc/backive/config"
|
"github.com/qwc/backive/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Backup contains all necessary information for executing a configured backup.
|
|
||||||
type Backup struct {
|
|
||||||
Name string `mapstructure:",omitempty"`
|
|
||||||
TargetDevice string `mapstructure:"targetDevice"`
|
|
||||||
TargetDir string `mapstructure:"targetDir"`
|
|
||||||
SourceDir string `mapstructure:"sourceDir"`
|
|
||||||
ScriptPath string `mapstructure:"scriptPath"`
|
|
||||||
Frequency int `mapstructure:"frequency"`
|
|
||||||
ExeUser string `mapstructure:"user,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run runs the backup script with appropriate rights.
|
// Run runs the backup script with appropriate rights.
|
||||||
func (b Backup) Run() error {
|
func Run(b backup.Backup) error {
|
||||||
cfg := config.Get()
|
cfg := config.Get()
|
||||||
if cfg.Devices[b.Name].isMounted() {
|
if cfg.Devices[b.Name].IsMounted() {
|
||||||
checkExistence := func(path string, name string) error {
|
checkExistence := func(path string, name string) error {
|
||||||
if _, err := os.Stat(path); err != nil {
|
if _, err := os.Stat(path); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
Loading…
Reference in New Issue