2023-10-12 15:42:36 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-07-03 11:33:02 +02:00
|
|
|
"context"
|
2023-10-12 15:42:36 +02:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
2024-07-03 11:33:02 +02:00
|
|
|
|
|
|
|
"github.com/netbirdio/netbird/formatter"
|
2024-12-11 12:58:45 +01:00
|
|
|
"github.com/netbirdio/netbird/management/server/store"
|
2024-07-03 11:33:02 +02:00
|
|
|
"github.com/netbirdio/netbird/util"
|
2023-10-12 15:42:36 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var shortUp = "Migrate JSON file store to SQLite store. Please make a backup of the JSON file before running this command."
|
|
|
|
|
|
|
|
var upCmd = &cobra.Command{
|
|
|
|
Use: "upgrade [--datadir directory] [--log-file console]",
|
|
|
|
Aliases: []string{"up"},
|
|
|
|
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 {
|
|
|
|
flag.Parse()
|
|
|
|
err := util.InitLog(logLevel, logFile)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed initializing log %v", err)
|
|
|
|
}
|
|
|
|
|
2024-07-03 11:33:02 +02:00
|
|
|
//nolint
|
|
|
|
ctx := context.WithValue(cmd.Context(), formatter.ExecutionContextKey, formatter.SystemSource)
|
|
|
|
|
2024-12-11 12:58:45 +01:00
|
|
|
if err := store.MigrateFileStoreToSqlite(ctx, mgmtDataDir); err != nil {
|
2024-06-13 12:39:19 +02:00
|
|
|
return err
|
2023-10-12 15:42:36 +02:00
|
|
|
}
|
2024-07-03 11:33:02 +02:00
|
|
|
log.WithContext(ctx).Info("Migration finished successfully")
|
2023-10-12 15:42:36 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|