2021-04-09 01:55:10 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2021-04-23 23:53:57 +02:00
|
|
|
"fmt"
|
|
|
|
|
2021-04-09 01:55:10 +02:00
|
|
|
"github.com/cupcakearmy/autorestic/internal"
|
2021-04-23 23:53:57 +02:00
|
|
|
"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-04-11 17:02:34 +02:00
|
|
|
err := lock.Lock()
|
|
|
|
CheckErr(err)
|
2021-04-09 01:55:10 +02:00
|
|
|
defer lock.Unlock()
|
2021-04-11 17:02:34 +02:00
|
|
|
|
2021-04-16 22:02:25 +02:00
|
|
|
CheckErr(internal.CheckConfig())
|
2021-04-11 17:02:34 +02:00
|
|
|
|
|
|
|
selected, err := internal.GetAllOrSelected(cmd, false)
|
|
|
|
CheckErr(err)
|
2021-04-23 23:53:57 +02:00
|
|
|
errors := 0
|
2021-04-11 17:02:34 +02:00
|
|
|
for _, name := range selected {
|
|
|
|
location, _ := internal.GetLocation(name)
|
2021-04-23 23:53:57 +02:00
|
|
|
err := location.Backup(false)
|
|
|
|
if err != nil {
|
|
|
|
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
|
|
|
}
|