Digital ID
Latest

Keycloak Backup

📆
🏷
, , ,

purpose and application

Use this procedure when you want to backup keycloak.

definitions

None.

steps

  1. stop keycloak rcctl stop keycloak
  2. become keycloak user su -s /bin/ksh -l _keycloak
  3. change into keycloak basedir cd keycloak
  4. export realms bash bin/kc.sh export --file ../backup/keycloak-$(date +%Y%m%dT%H%M%S)

Resources

https://www.keycloak.org/server/importExport

Keycloak Upgrade 22.0.5 -> 24.0.3

📆
🏷
, ,

After running into more or less the same problem every damn keycloak upgrade it’s time to put some notes into place so I won’t struggle in the future anymore. At least not with the same problem.

  • Change into the root directory for keycloak

    cd /var/www
    
  • Download the latest release tarball

    curl -LO https://github.com/keycloak/keycloak/releases/download/24.0.3/keycloak-24.0.3.tar.gz
    
  • Change ownership

    chown _keycloak keycloak-24.0.3
    
  • Read the upgrade instructions! Most of the time it boils down to

    cp -Rpv keycloak-22.0.5/{conf,providers,themes} keycloak-24.0.3/
    

    for me

  • Change into the new release directory

    cd keycloak-24.0.3/
    
  • Stop old keycloak

    rcctl stop keycloak
    
  • This step is crucial and well hidden within the documentation of keycloak.

    JAVA_HOME=/usr/local/jdk-21 bin/kc.sh build
    

    Failing to do the build first before starting keycloak with the --optimized flag via my rc file results in an exception due to problems with the jdbc URL:

    2024-04-19 13:38:08,815 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: URL format error; must be "jdbc:h2:{ {.|mem:}[name] | [file:]fileName | {tcp|ssl}:[//]server[:port][,server2[:port]]/name }[;key=value...]" but is "jdbc:postgresql://localhost:5432/keycloak" [90046-224]
    
  • adjust daemon_execdir to reflect the new version in /etc/rc.d/keycloak

  • Start the new keycloak

    rcctl start keycloak
    
  • Clean up behind you

    rm -rd /var/www/keycloak-22.0.5