mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-18 05:47:32 +00:00
c9b3839f3d
* 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 041cacc4af8aeb89723a049bc4dbfcbc33cd987f) * fix: gitops backup and restore need a kubernetes client too (#1475) (cherry picked from commit 50bc317d2797b819124cdb1119db76bb00ab0df6) Co-authored-by: Elio Bischof <eliobischof@gmail.com>
64 lines
1.2 KiB
Go
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
|
|
}
|