show_dump

package
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Cmd = &cobra.Command{
		Use:   "show-dump [flags] dumpId|latest",
		Args:  cobra.ExactArgs(1),
		Short: "shows metadata info about the dump (the same as pg_restore -l ./)",
		Run: func(cmd *cobra.Command, args []string) {
			var dumpId string

			if err := logger.SetLogLevel(Config.Log.Level, Config.Log.Format); err != nil {
				log.Fatal().Err(err).Msg("error setting up logger")
			}

			ctx, cancel := context.WithCancel(context.Background())
			defer cancel()
			st, err := builder.GetStorage(ctx, &Config.Storage, &Config.Log)
			if err != nil {
				log.Fatal().Err(err).Msg("error building storage")
			}

			if args[0] == "latest" {
				var backupNames []string

				_, dirs, err := st.ListDir(ctx)
				if err != nil {
					log.Fatal().Err(err).Msg("cannot walk through directory")
				}
				for _, dir := range dirs {
					exists, err := dir.Exists(ctx, "metadata.json")
					if err != nil {
						log.Fatal().Err(err).Msg("cannot check file existence")
					}
					if exists {
						backupNames = append(backupNames, dir.Dirname())
					}
				}

				slices.SortFunc(backupNames, func(a, b string) int {
					if a > b {
						return -1
					}
					return 1
				})
				dumpId = backupNames[0]
			} else {
				dumpId = args[0]
				exists, err := st.Exists(ctx, path.Join(dumpId, "metadata.json"))
				if err != nil {
					log.Fatal().Err(err).Msg("cannot check file existence")
				}
				if !exists {
					log.Fatal().Msgf("choose another dump %s is failed", dumpId)
				}
			}

			if err := cmdInternals.ShowDump(ctx, st, dumpId, format); err != nil {
				log.Fatal().Err(err).Msg("")
			}
		},
	}
)
View Source
var (
	Config = pgDomains.NewConfig()
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL