diff --git a/management/cmd/rollback.go b/management/cmd/migration_down.go similarity index 86% rename from management/cmd/rollback.go rename to management/cmd/migration_down.go index 0b5e00e3e38..f5d8e4c2071 100644 --- a/management/cmd/rollback.go +++ b/management/cmd/migration_down.go @@ -13,12 +13,12 @@ import ( "github.com/spf13/cobra" ) -var shortRollback = "Rollback SQLite store to JSON filestore. Please make a backup of the SQLite file before running this command." +var shortDown = "Rollback SQLite store to JSON filestore. Please make a backup of the SQLite file before running this command." -var rollbackCmd = &cobra.Command{ - Use: "rollback [--datadir directory] [--log-file console]", - Short: shortRollback, - Long: shortRollback + +var downCmd = &cobra.Command{ + Use: "down [--datadir directory] [--log-file console]", + Short: shortDown, + Long: shortDown + "\n\n" + "This command reads the content of {datadir}/store.db and migrates it to {datadir}/store.json that can be used by File store driver.", RunE: func(cmd *cobra.Command, args []string) error { diff --git a/management/cmd/migration.go b/management/cmd/migration_up.go similarity index 86% rename from management/cmd/migration.go rename to management/cmd/migration_up.go index 34b7c6386fa..ba3b61d0b7a 100644 --- a/management/cmd/migration.go +++ b/management/cmd/migration_up.go @@ -13,12 +13,12 @@ import ( "github.com/spf13/cobra" ) -var shortMigration = "Migrate JSON file store to SQLite store. Please make a backup of the store json file before running this command." +var shortUp = "Migrate JSON file store to SQLite store. Please make a backup of the JSON file before running this command." -var migrationCmd = &cobra.Command{ - Use: "migration [--datadir directory] [--log-file console]", - Short: shortMigration, - Long: shortMigration + +var upCmd = &cobra.Command{ + Use: "up [--datadir directory] [--log-file console]", + Short: shortUp, + Long: shortUp + "\n\n" + "This command reads the content of {datadir}/store.json and migrates it to {datadir}/store.db that can be used by SQLite store driver.", RunE: func(cmd *cobra.Command, args []string) error { diff --git a/management/cmd/root.go b/management/cmd/root.go index b3338511af2..b43d490cf2a 100644 --- a/management/cmd/root.go +++ b/management/cmd/root.go @@ -34,6 +34,12 @@ var ( SilenceUsage: true, } + migrationCmd = &cobra.Command{ + Use: "sqlite-migration", + Short: "Contains sub commands to perform filesotre to sqlite store migration and rollback", + Long: "", + SilenceUsage: true, + } // Execution control channel for stopCh signal stopCh chan int ) @@ -64,13 +70,13 @@ func init() { rootCmd.PersistentFlags().StringVar(&logFile, "log-file", defaultLogFile, "sets Netbird log path. If console is specified the the log will be output to stdout") rootCmd.AddCommand(mgmtCmd) - migrationCmd.Flags().StringVar(&mgmtDataDir, "datadir", defaultMgmtDataDir, "server data directory location") + migrationCmd.PersistentFlags().StringVar(&mgmtDataDir, "datadir", defaultMgmtDataDir, "server data directory location") migrationCmd.MarkFlagRequired("datadir") //nolint - rootCmd.AddCommand(migrationCmd) - rollbackCmd.Flags().StringVar(&mgmtDataDir, "datadir", defaultMgmtDataDir, "server data directory location") - rollbackCmd.MarkFlagRequired("datadir") //nolint - rootCmd.AddCommand(rollbackCmd) + migrationCmd.AddCommand(upCmd) + migrationCmd.AddCommand(downCmd) + + rootCmd.AddCommand(migrationCmd) } // SetupCloseHandler handles SIGTERM signal and exits with success