parent
3103fbde29
commit
dd23da80ee
36
main.go
36
main.go
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/hcl/v2"
|
"github.com/hashicorp/hcl/v2"
|
||||||
@ -117,6 +118,7 @@ func FilterJobs(jobs []Job, names []string) ([]Job, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filteredJobs := []Job{}
|
filteredJobs := []Job{}
|
||||||
|
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
if nameSet.Contains(job.Name) {
|
if nameSet.Contains(job.Name) {
|
||||||
filteredJobs = append(filteredJobs, job)
|
filteredJobs = append(filteredJobs, job)
|
||||||
@ -133,24 +135,30 @@ func FilterJobs(jobs []Job, names []string) ([]Job, error) {
|
|||||||
return filteredJobs, err
|
return filteredJobs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunBackupJobs(jobs []Job) error {
|
func runBackupJobs(jobs []Job, names string) error {
|
||||||
|
namesSlice := strings.Split(names, ",")
|
||||||
|
|
||||||
|
jobs, filterJobErr := FilterJobs(jobs, namesSlice)
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
if err := job.RunBackup(); err != nil {
|
if err := job.RunBackup(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return filterJobErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunRestoreJobs(jobs []Job) error {
|
func runRestoreJobs(jobs []Job, names string) error {
|
||||||
|
namesSlice := strings.Split(names, ",")
|
||||||
|
|
||||||
|
jobs, filterJobErr := FilterJobs(jobs, namesSlice)
|
||||||
for _, job := range jobs {
|
for _, job := range jobs {
|
||||||
if err := job.RunRestore(); err != nil {
|
if err := job.RunRestore(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return filterJobErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -169,6 +177,10 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, err := exec.LookPath("restic"); err != nil {
|
||||||
|
log.Fatalf("Could not find restic in path. Make sure it's installed")
|
||||||
|
}
|
||||||
|
|
||||||
if flag.NArg() == 0 {
|
if flag.NArg() == 0 {
|
||||||
log.Fatalf("Requires a path to a job file, but found none")
|
log.Fatalf("Requires a path to a job file, but found none")
|
||||||
}
|
}
|
||||||
@ -183,27 +195,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run specified backup jobs
|
// Run specified backup jobs
|
||||||
backupJobNames := strings.Split(*backup, ",")
|
if err := runBackupJobs(jobs, *backup); err != nil {
|
||||||
backupJobs, filterJobErr := FilterJobs(jobs, backupJobNames)
|
|
||||||
if err := RunBackupJobs(backupJobs); err != nil {
|
|
||||||
log.Fatalf("Failed running backup jobs: %v", err)
|
log.Fatalf("Failed running backup jobs: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if filterJobErr != nil {
|
|
||||||
log.Fatalf("Unkown backup job: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run specified restore jobs
|
// Run specified restore jobs
|
||||||
restoreJobNames := strings.Split(*restore, ",")
|
if err := runRestoreJobs(jobs, *restore); err != nil {
|
||||||
restoreJobs, filterJobErr := FilterJobs(jobs, restoreJobNames)
|
|
||||||
if err := RunRestoreJobs(restoreJobs); err != nil {
|
|
||||||
log.Fatalf("Failed running restore jobs: %v", err)
|
log.Fatalf("Failed running restore jobs: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if filterJobErr != nil {
|
|
||||||
log.Fatalf("Unkown restore job: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exit if only running once
|
// Exit if only running once
|
||||||
if *once {
|
if *once {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user