2021-04-08 23:55:10 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-04-23 21:53:57 +00:00
|
|
|
"fmt"
|
2021-10-28 15:29:32 +00:00
|
|
|
"strings"
|
2021-04-23 21:53:57 +00:00
|
|
|
|
2021-04-08 23:55:10 +00:00
|
|
|
"github.com/cupcakearmy/autorestic/internal"
|
2021-04-23 21:53:57 +00:00
|
|
|
"github.com/cupcakearmy/autorestic/internal/colors"
|
2021-04-08 23:55:10 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var backupCmd = &cobra.Command{
|
|
|
|
Use: "backup",
|
2021-04-11 11:08:50 +00:00
|
|
|
Short: "Create backups for given locations",
|
2021-04-08 23:55:10 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2021-08-05 19:48:02 +00:00
|
|
|
internal.GetConfig()
|
2024-11-10 18:37:59 +00:00
|
|
|
err := internal.Lock()
|
2021-04-11 15:02:34 +00:00
|
|
|
CheckErr(err)
|
2024-11-10 18:37:59 +00:00
|
|
|
defer internal.Unlock()
|
2021-04-11 15:02:34 +00:00
|
|
|
|
|
|
|
selected, err := internal.GetAllOrSelected(cmd, false)
|
|
|
|
CheckErr(err)
|
2021-04-23 21:53:57 +00:00
|
|
|
errors := 0
|
2021-04-11 15:02:34 +00:00
|
|
|
for _, name := range selected {
|
2021-10-28 15:29:32 +00: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 21:31:31 +00:00
|
|
|
for _, err := range errs {
|
2021-12-06 11:13:18 +00:00
|
|
|
colors.Error.Printf("%s\n\n", err)
|
2021-04-23 21:53:57 +00:00
|
|
|
errors++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if errors > 0 {
|
|
|
|
CheckErr(fmt.Errorf("%d errors were found", errors))
|
2021-04-08 23:55:10 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(backupCmd)
|
2021-04-11 11:04:11 +00:00
|
|
|
internal.AddFlagsToCommand(backupCmd, false)
|
2021-04-08 23:55:10 +00:00
|
|
|
}
|