-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added create/restore from snapshot commands
- Loading branch information
1 parent
f90bc85
commit 47ab80f
Showing
9 changed files
with
607 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Layr-Labs/sidecar/internal/config" | ||
"github.com/Layr-Labs/sidecar/internal/logger" | ||
"github.com/Layr-Labs/sidecar/pkg/snapshot" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var createSnapshotCmd = &cobra.Command{ | ||
Use: "create-snapshot", | ||
Short: "Create a snapshot of the database", | ||
Long: "Create a snapshot of the database.", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
initCreateSnapshotCmd(cmd) | ||
cfg := config.NewConfig() | ||
|
||
l, err := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize logger: %w", err) | ||
} | ||
|
||
sCfg := snapshot.NewSnapshotConfig(cfg, l) | ||
|
||
if err := snapshot.CreateSnapshot(sCfg); err != nil { | ||
return fmt.Errorf("failed to create snapshot: %w", err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func initCreateSnapshotCmd(cmd *cobra.Command) { | ||
cmd.Flags().VisitAll(func(f *pflag.Flag) { | ||
if err := viper.BindPFlag(config.KebabToSnakeCase(f.Name), f); err != nil { | ||
fmt.Printf("Failed to bind flag '%s' - %+v\n", f.Name, err) | ||
} | ||
if err := viper.BindEnv(f.Name); err != nil { | ||
fmt.Printf("Failed to bind env '%s' - %+v\n", f.Name, err) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Layr-Labs/sidecar/internal/config" | ||
"github.com/Layr-Labs/sidecar/internal/logger" | ||
"github.com/Layr-Labs/sidecar/pkg/snapshot" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var restoreSnapshotCmd = &cobra.Command{ | ||
Use: "restore-snapshot", | ||
Short: "Restore database from a snapshot file", | ||
Long: `Restore the database from a previously created snapshot file. | ||
The snapshot file is expected to be a pg_dump custom format file.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
initRestoreSnapshotCmd(cmd) | ||
cfg := config.NewConfig() | ||
|
||
l, err := logger.NewLogger(&logger.LoggerConfig{Debug: cfg.Debug}) | ||
if err != nil { | ||
return fmt.Errorf("failed to initialize logger: %w", err) | ||
} | ||
|
||
sCfg := snapshot.NewSnapshotConfig(cfg, l) | ||
|
||
if err := snapshot.RestoreSnapshot(sCfg); err != nil { | ||
return fmt.Errorf("failed to restore snapshot: %w", err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func initRestoreSnapshotCmd(cmd *cobra.Command) { | ||
cmd.Flags().VisitAll(func(f *pflag.Flag) { | ||
if err := viper.BindPFlag(config.KebabToSnakeCase(f.Name), f); err != nil { | ||
fmt.Printf("Failed to bind flag '%s' - %+v\n", f.Name, err) | ||
} | ||
if err := viper.BindEnv(f.Name); err != nil { | ||
fmt.Printf("Failed to bind env '%s' - %+v\n", f.Name, err) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.