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:
|
||||
- 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:
|
||||
|
|
|
@ -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 (
|
||||
"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 {
|
||||
|
|
|
@ -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 {
|
|
@ -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) {
|
Loading…
Reference in New Issue