Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 51764a677a | |||
| bdbbb59e51 | |||
| 1a6ea13222 |
23
cmd/root.go
23
cmd/root.go
@ -15,11 +15,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
cfg *config.Config
|
||||
log logger.Logger
|
||||
auditLogger *security.AuditLogger
|
||||
rateLimiter *security.RateLimiter
|
||||
notifyManager *notify.Manager
|
||||
cfg *config.Config
|
||||
log logger.Logger
|
||||
auditLogger *security.AuditLogger
|
||||
rateLimiter *security.RateLimiter
|
||||
notifyManager *notify.Manager
|
||||
deprecatedPassword string
|
||||
)
|
||||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
@ -47,6 +48,11 @@ For help with specific commands, use: dbbackup [command] --help`,
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check for deprecated password flag
|
||||
if deprecatedPassword != "" {
|
||||
return fmt.Errorf("--password flag is not supported for security reasons. Use environment variables instead:\n - MySQL/MariaDB: export MYSQL_PWD='your_password'\n - PostgreSQL: export PGPASSWORD='your_password' or use .pgpass file")
|
||||
}
|
||||
|
||||
// Store which flags were explicitly set by user
|
||||
flagsSet := make(map[string]bool)
|
||||
cmd.Flags().Visit(func(f *pflag.Flag) {
|
||||
@ -171,15 +177,8 @@ func Execute(ctx context.Context, config *config.Config, logger logger.Logger) e
|
||||
rootCmd.PersistentFlags().StringVar(&cfg.Database, "database", cfg.Database, "Database name")
|
||||
// SECURITY: Password flag removed - use PGPASSWORD/MYSQL_PWD environment variable or .pgpass file
|
||||
// Provide helpful error message for users expecting --password flag
|
||||
var deprecatedPassword string
|
||||
rootCmd.PersistentFlags().StringVar(&deprecatedPassword, "password", "", "DEPRECATED: Use MYSQL_PWD or PGPASSWORD environment variable instead")
|
||||
rootCmd.PersistentFlags().MarkHidden("password")
|
||||
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
|
||||
if deprecatedPassword != "" {
|
||||
return fmt.Errorf("--password flag is not supported for security reasons. Use environment variables instead:\n - MySQL/MariaDB: export MYSQL_PWD='your_password'\n - PostgreSQL: export PGPASSWORD='your_password' or use .pgpass file")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
rootCmd.PersistentFlags().StringVarP(&cfg.DatabaseType, "db-type", "d", cfg.DatabaseType, "Database type (postgres|mysql|mariadb)")
|
||||
rootCmd.PersistentFlags().StringVar(&cfg.BackupDir, "backup-dir", cfg.BackupDir, "Backup directory")
|
||||
rootCmd.PersistentFlags().BoolVar(&cfg.NoColor, "no-color", cfg.NoColor, "Disable colored output")
|
||||
|
||||
@ -205,11 +205,13 @@ func (m ArchiveBrowserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return diagnoseView, diagnoseView.Init()
|
||||
}
|
||||
|
||||
// For restore-cluster mode:
|
||||
// - .tar.gz cluster archives → full cluster restore
|
||||
// - .sql/.sql.gz files → single database restore (Native Engine supports these)
|
||||
// - .dump/.dump.gz → single database restore (pg_restore)
|
||||
// ALL formats are now allowed for restore operations!
|
||||
// For restore-cluster mode: MUST be a .tar.gz cluster archive created by this tool
|
||||
// pg_dumpall SQL files should be restored via CLI: psql -f <file.sql>
|
||||
if m.mode == "restore-cluster" && !selected.Format.IsClusterBackup() {
|
||||
m.message = errorStyle.Render(fmt.Sprintf("⚠️ %s is not a dbbackup cluster archive (.tar.gz).\n\n If this is a pg_dumpall SQL file, restore it via CLI:\n psql -h %s -p %d -U %s -f %s",
|
||||
selected.Name, m.config.Host, m.config.Port, m.config.User, selected.Path))
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// For single restore mode with cluster backup selected - offer to select individual database
|
||||
if m.mode == "restore-single" && selected.Format.IsClusterBackup() {
|
||||
@ -217,7 +219,7 @@ func (m ArchiveBrowserModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return clusterSelector, clusterSelector.Init()
|
||||
}
|
||||
|
||||
// Open restore preview for any valid format
|
||||
// Open restore preview for valid format
|
||||
preview := NewRestorePreview(m.config, m.logger, m.parent, m.ctx, selected, m.mode)
|
||||
return preview, preview.Init()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user