mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-11-05 13:14:48 +01:00
43 lines
897 B
Go
43 lines
897 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/cupcakearmy/autorestic/internal"
|
|
"github.com/cupcakearmy/autorestic/internal/colors"
|
|
"github.com/cupcakearmy/autorestic/internal/lock"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var backupCmd = &cobra.Command{
|
|
Use: "backup",
|
|
Short: "Create backups for given locations",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
err := lock.Lock()
|
|
CheckErr(err)
|
|
defer lock.Unlock()
|
|
|
|
CheckErr(internal.CheckConfig())
|
|
|
|
selected, err := internal.GetAllOrSelected(cmd, false)
|
|
CheckErr(err)
|
|
errors := 0
|
|
for _, name := range selected {
|
|
location, _ := internal.GetLocation(name)
|
|
err := location.Backup(false)
|
|
if err != nil {
|
|
colors.Error.Println(err)
|
|
errors++
|
|
}
|
|
}
|
|
if errors > 0 {
|
|
CheckErr(fmt.Errorf("%d errors were found", errors))
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(backupCmd)
|
|
internal.AddFlagsToCommand(backupCmd, false)
|
|
}
|