backive/runner/runner.go

43 lines
1.1 KiB
Go
Raw Normal View History

package runner
2021-10-12 23:00:24 +02:00
2021-11-14 15:07:20 +01:00
import (
"fmt"
"os"
"github.com/qwc/backive/backup"
2021-11-14 15:07:20 +01:00
"github.com/qwc/backive/config"
)
// Run runs the backup script with appropriate rights.
func Run(b backup.Backup) error {
2021-11-14 15:07:20 +01:00
cfg := config.Get()
if cfg.Devices[b.Name].IsMounted() {
2021-11-14 15:07:20 +01:00
checkExistence := func(path string, name string) error {
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("%s does not exist", name)
} else {
return fmt.Errorf("Error when checking %s: %w", name, err)
}
}
return nil
}
// Check for existence of target dir
if err := checkExistence(b.TargetDir, "target directory"); err != nil {
return err
}
// check for existence of source dir
if err := checkExistence(b.SourceDir, "source directory"); err != nil {
return err
}
// check for existence of script path
if err := checkExistence(b.ScriptPath, "script path"); err != nil {
return err
}
// setup script environment including user to use
// run script
}
// quit with error that the device is not available.
return fmt.Errorf("The device is not mounted")
}