2021-04-08 23:55:10 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/cupcakearmy/autorestic/internal"
|
|
|
|
"github.com/cupcakearmy/autorestic/internal/lock"
|
|
|
|
"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-04-11 15:02:34 +00:00
|
|
|
err := lock.Lock()
|
|
|
|
CheckErr(err)
|
2021-04-08 23:55:10 +00:00
|
|
|
defer lock.Unlock()
|
2021-04-11 15:02:34 +00:00
|
|
|
|
2021-04-16 20:02:25 +00:00
|
|
|
CheckErr(internal.CheckConfig())
|
2021-04-11 15:02:34 +00:00
|
|
|
|
|
|
|
selected, err := internal.GetAllOrSelected(cmd, false)
|
|
|
|
CheckErr(err)
|
|
|
|
for _, name := range selected {
|
|
|
|
location, _ := internal.GetLocation(name)
|
|
|
|
location.Backup()
|
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
|
|
|
}
|