Search code examples
keycloak

How to backup KeyCloak before reinstalling


How to backup KeyCloak config before reinstalling? I mean how did the author export such file https://github.com/Baeldung/spring-security-oauth/blob/master/oauth-rest/oauth-authorization-server/src/main/resources/baeldung-realm.json

I have tried ./bin/kc.sh export --file and ./bin/kcadm.sh get realms/myrealm

But these exports only partial information. I need to export everything.


Solution

  • If you want to export only one realm with clients you can use:

    in/kc.[sh|bat] export [--dir|--file] <path> --realm my-realm
    

    E.g.

    kc.sh export --dir /home/me/KCbackup/ --realm Prod 
    

    For the import you can use:

    bin/kc.[sh|bat] import --dir <dir> --override false
    

    Also, I would raccomand to do an export of the database, so that in case of errors you can import it again.

    If you need more information you can follow the docs: https://www.keycloak.org/server/importExport