diff --git a/.goreleaser.yml b/.goreleaser.yml index a2f4c85..1bbb182 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -9,6 +9,7 @@ before: builds: - main: ./cmd/backive/main.go id: backive + binary: backive env: - CGO_ENABLED=0 goarch: @@ -19,6 +20,7 @@ builds: # - darwin - main: ./cmd/backive_udev/main.go id: backive_udev + binary: backive_udev goarch: - amd64 env: @@ -29,6 +31,7 @@ builds: # - darwin - main: ./cmd/backive_ui/main.go id: backive_ui + binary: backive_ui env: - CGO_ENABLED=0 goarch: diff --git a/backup/backup.go b/backup/backup.go new file mode 100644 index 0000000..28342a5 --- /dev/null +++ b/backup/backup.go @@ -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"` +} diff --git a/config/config.go b/config/config.go index 6a362c8..2143202 100644 --- a/config/config.go +++ b/config/config.go @@ -3,7 +3,8 @@ package config import ( "fmt" - "github.com/qwc/backive/core" + "github.com/qwc/backive/backup" + "github.com/qwc/backive/device" "github.com/spf13/viper" ) @@ -27,10 +28,10 @@ type Settings struct { } // 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 -type Backups map[string]core.Backup +type Backups map[string]backup.Backup // CreateViper creates a viper instance for usage later func CreateViper() *viper.Viper { diff --git a/core/device.go b/device/device.go similarity index 97% rename from core/device.go rename to device/device.go index 79b06f9..2bd6ac4 100644 --- a/core/device.go +++ b/device/device.go @@ -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. type Device struct { diff --git a/core/backup.go b/runner/runner.go similarity index 65% rename from core/backup.go rename to runner/runner.go index cd7ed11..767ebfe 100644 --- a/core/backup.go +++ b/runner/runner.go @@ -1,27 +1,17 @@ -package core +package runner import ( "fmt" "os" + "github.com/qwc/backive/backup" "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. -func (b Backup) Run() error { +func Run(b backup.Backup) error { cfg := config.Get() - if cfg.Devices[b.Name].isMounted() { + if cfg.Devices[b.Name].IsMounted() { checkExistence := func(path string, name string) error { if _, err := os.Stat(path); err != nil { if os.IsNotExist(err) {