mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-10 13:13:46 +00:00
55 lines
1015 B
Go
55 lines
1015 B
Go
|
package cmds
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"sort"
|
||
|
|
||
|
"github.com/caos/zitadel/pkg/databases"
|
||
|
"github.com/spf13/cobra"
|
||
|
)
|
||
|
|
||
|
func BackupListCommand(rv RootValues) *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 {
|
||
|
_, monitor, orbConfig, gitClient, _, errFunc, err := rv()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer func() {
|
||
|
err = errFunc(err)
|
||
|
}()
|
||
|
|
||
|
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
|
||
|
}
|