zitadel/cmd/zitadelctl/cmds/backuplist.go
Livio Amstutz c9b3839f3d
fix: operator reconciling (#1478)
* fix(operator): align backup and restore commands (#1465)

* fix: crd mode broke backup and restore commands

* fix: remove obscure gitops-per-operator flags

(cherry picked from commit 041cacc4af)

* fix: gitops backup and restore need a kubernetes client too (#1475)

(cherry picked from commit 50bc317d27)

Co-authored-by: Elio Bischof <eliobischof@gmail.com>
2021-03-25 16:39:19 +01:00

64 lines
1.2 KiB
Go

package cmds
import (
"errors"
"fmt"
"sort"
"github.com/caos/zitadel/pkg/databases"
"github.com/spf13/cobra"
)
func BackupListCommand(getRv GetRootValues) *cobra.Command {
var (
cmd = &cobra.Command{
Use: "backuplist",
Short: "Get a list of all backups",
Long: "Get a list of all backups",
}
)
cmd.RunE = func(cmd *cobra.Command, args []string) error {
rv, err := getRv()
if err != nil {
return err
}
defer func() {
err = rv.ErrFunc(err)
}()
monitor := rv.Monitor
orbConfig := rv.OrbConfig
gitClient := rv.GitClient
if !rv.Gitops {
return errors.New("backuplist command is only supported with the --gitops flag yet")
}
if err := gitClient.Configure(orbConfig.URL, []byte(orbConfig.Repokey)); err != nil {
monitor.Error(err)
return nil
}
if err := gitClient.Clone(); err != nil {
monitor.Error(err)
return nil
}
backups, err := databases.ListBackups(monitor, gitClient)
if err != nil {
monitor.Error(err)
return nil
}
sort.Slice(backups, func(i, j int) bool {
return backups[i] > backups[j]
})
for _, backup := range backups {
fmt.Println(backup)
}
return nil
}
return cmd
}