mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-11-05 05:04:13 +01:00
Merge pull request #117 from cupcakearmy/specific-location
specific location
This commit is contained in:
commit
3e80e6d18e
@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/cupcakearmy/autorestic/internal"
|
||||
"github.com/cupcakearmy/autorestic/internal/colors"
|
||||
@ -22,8 +23,13 @@ var backupCmd = &cobra.Command{
|
||||
CheckErr(err)
|
||||
errors := 0
|
||||
for _, name := range selected {
|
||||
location, _ := internal.GetLocation(name)
|
||||
errs := location.Backup(false)
|
||||
var splitted = strings.Split(name, "@")
|
||||
var specificBackend = ""
|
||||
if len(splitted) > 1 {
|
||||
specificBackend = splitted[1]
|
||||
}
|
||||
location, _ := internal.GetLocation(splitted[0])
|
||||
errs := location.Backup(false, specificBackend)
|
||||
for err := range errs {
|
||||
colors.Error.Println(err)
|
||||
errors++
|
||||
|
@ -185,20 +185,18 @@ func GetAllOrSelected(cmd *cobra.Command, backends bool) ([]string, error) {
|
||||
selected, _ = cmd.Flags().GetStringSlice("location")
|
||||
}
|
||||
for _, s := range selected {
|
||||
found := false
|
||||
var splitted = strings.Split(s, "@")
|
||||
for _, l := range list {
|
||||
if l == s {
|
||||
found = true
|
||||
break
|
||||
if l == splitted[0] {
|
||||
goto found
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
if backends {
|
||||
return nil, fmt.Errorf("invalid backend \"%s\"", s)
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalid location \"%s\"", s)
|
||||
}
|
||||
if backends {
|
||||
return nil, fmt.Errorf("invalid backend \"%s\"", s)
|
||||
} else {
|
||||
return nil, fmt.Errorf("invalid location \"%s\"", s)
|
||||
}
|
||||
found:
|
||||
}
|
||||
|
||||
if len(selected) == 0 {
|
||||
|
@ -125,8 +125,9 @@ func (l Location) getPath() (string, error) {
|
||||
return "", fmt.Errorf("could not get path for location \"%s\"", l.name)
|
||||
}
|
||||
|
||||
func (l Location) Backup(cron bool) []error {
|
||||
func (l Location) Backup(cron bool, specificBackend string) []error {
|
||||
var errors []error
|
||||
var backends []string
|
||||
colors.PrimaryPrint(" Backing up location \"%s\" ", l.name)
|
||||
t := l.getType()
|
||||
options := ExecuteOptions{
|
||||
@ -155,7 +156,20 @@ func (l Location) Backup(cron bool) []error {
|
||||
}
|
||||
|
||||
// Backup
|
||||
for i, to := range l.To {
|
||||
if specificBackend == "" {
|
||||
backends = l.To
|
||||
} else {
|
||||
for _, b := range l.To {
|
||||
if b == specificBackend {
|
||||
backends = []string{b}
|
||||
goto backup
|
||||
}
|
||||
}
|
||||
errors = append(errors, fmt.Errorf("backup location \"%s\" has no backend \"%s\"", l.name, specificBackend))
|
||||
return errors
|
||||
}
|
||||
backup:
|
||||
for i, to := range backends {
|
||||
backend, _ := GetBackend(to)
|
||||
colors.Secondary.Printf("Backend: %s\n", backend.name)
|
||||
env, err := backend.getEnv()
|
||||
@ -338,7 +352,7 @@ func (l Location) RunCron() error {
|
||||
now := time.Now()
|
||||
if now.After(next) {
|
||||
lock.SetCron(l.name, now.Unix())
|
||||
l.Backup(true)
|
||||
l.Backup(true, "")
|
||||
} else {
|
||||
if !CRON_LEAN {
|
||||
colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name)
|
||||
|
Loading…
Reference in New Issue
Block a user