You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
autorestic/cmd/backup.go

42 lines
893 B

4 years ago
package cmd
import (
"fmt"
4 years ago
"github.com/cupcakearmy/autorestic/internal"
"github.com/cupcakearmy/autorestic/internal/colors"
4 years ago
"github.com/cupcakearmy/autorestic/internal/lock"
"github.com/spf13/cobra"
)
var backupCmd = &cobra.Command{
Use: "backup",
4 years ago
Short: "Create backups for given locations",
4 years ago
Run: func(cmd *cobra.Command, args []string) {
internal.GetConfig()
err := lock.Lock()
CheckErr(err)
4 years ago
defer lock.Unlock()
selected, err := internal.GetAllOrSelected(cmd, false)
CheckErr(err)
errors := 0
for _, name := range selected {
location, _ := internal.GetLocation(name)
errs := location.Backup(false)
for err := range errs {
colors.Error.Println(err)
errors++
}
}
if errors > 0 {
CheckErr(fmt.Errorf("%d errors were found", errors))
4 years ago
}
},
}
func init() {
rootCmd.AddCommand(backupCmd)
4 years ago
internal.AddFlagsToCommand(backupCmd, false)
4 years ago
}