autorestic/cmd/backup.go

48 lines
1.0 KiB
Go
Raw Normal View History

2021-04-09 01:55:10 +02:00
package cmd
import (
"fmt"
2021-10-28 17:29:32 +02:00
"strings"
2021-04-09 01:55:10 +02:00
"github.com/cupcakearmy/autorestic/internal"
"github.com/cupcakearmy/autorestic/internal/colors"
2021-04-09 01:55:10 +02:00
"github.com/cupcakearmy/autorestic/internal/lock"
"github.com/spf13/cobra"
)
var backupCmd = &cobra.Command{
Use: "backup",
2021-04-11 13:08:50 +02:00
Short: "Create backups for given locations",
2021-04-09 01:55:10 +02:00
Run: func(cmd *cobra.Command, args []string) {
2021-08-05 21:48:02 +02:00
internal.GetConfig()
err := lock.Lock()
CheckErr(err)
2021-04-09 01:55:10 +02:00
defer lock.Unlock()
selected, err := internal.GetAllOrSelected(cmd, false)
CheckErr(err)
errors := 0
for _, name := range selected {
2021-10-28 17:29:32 +02:00
var splitted = strings.Split(name, "@")
var specificBackend = ""
if len(splitted) > 1 {
specificBackend = splitted[1]
}
location, _ := internal.GetLocation(splitted[0])
errs := location.Backup(false, specificBackend)
2021-10-31 22:31:31 +01:00
for _, err := range errs {
colors.Error.Println(err)
errors++
}
}
if errors > 0 {
CheckErr(fmt.Errorf("%d errors were found", errors))
2021-04-09 01:55:10 +02:00
}
},
}
func init() {
rootCmd.AddCommand(backupCmd)
2021-04-11 13:04:11 +02:00
internal.AddFlagsToCommand(backupCmd, false)
2021-04-09 01:55:10 +02:00
}