Export / Import realms : why the server must be stoped?

In Importing and Exporting Realms - Keycloak, it is mentioned

To export a realm, you can use the export command. Your Keycloak server instance must not be started when invoking this command.

To import a realm, you can use the import command. Your Keycloak server instance must not be started when invoking this command.

For us, stoping a server means killing a k8s stateful sets and losing all sessions

So why is there such a restriction ?

Please note that I plan to export realms WITHOUT users (but I hope with clients and service accounts) and to import the realms after fresh startup in order to sync the dev env with the prod env

Edit : I should add that previously the export/import was possible directly from the admin console, so it’s only because of the move to the new admin console that we have the problem

Just because the new admin console (which is still PREVIEW!!!) doesn’t support import/export of realm resources, this doesn’t mean that it’s no more possible. The API behind the admin ui hasn’t changed, so you can still do the export you did with the legacy admin ui through a direct API call. Then, you get the exported realm data.

Regarding the restriction for the im-/export on the CLI - there’s only this answer to your question: it is a design decision from the team. Im-/Export of data on CLI was and is never meant to be executed during a running/operating environment. :man_shrugging:

1 Like

Thanks for the answerr @dasniko

Ok to do the API call instead of the preview admin-ui … but the KC 18 announcement said that it’s going to be used in GA in KC 19, so can we expect to have this feature “back” ?

Or should I post somewhere else about this (github issue or something) ?

The new admin UI will be going GA, yes, but the admin API will remain unchanged. The old and the new admin UI are using the admin API. You can call the API also directly from an e.g. shell script. So you can script your export request.

Additionally, you can extend/customize the old and the new admin UI and add the functionality you desire. You are free to add an “export” option in your custom admin UI theme. Then, you get it back. Perhaps the Keycloak team just has forgotten to add the import/export options and it will be available with GA. Perhaps not. Don’t know.