Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keycloak backup operation

I'm reading the documentation from Keycloak for the export operation in order to setup a backup operation (e.g. via a cron job) and what it says is that export is happending during server startup:

Export and import is triggered at server boot time and its parameters are passed in via Java system properties. It is important to note that because import and export happens at server startup, no other actions should be taken on the server or the database while this happens.

While it has a point, that no other operation is happening during the export operation I was wondering what is the best practice to keep backups of your existing keycloak data? Should the cron job for instance reboot the keycloak server every one per Week to keep the backup, or should I consider a backup operation on the database side (RDBMS)?

like image 696
tbo Avatar asked Jan 10 '17 09:01

tbo


People also ask

How do I export a Keycloak database?

To export a realm, you can use the export command. Your Keycloak server instance must not be started when invoking this command. To export a realm to a directory, you can use the --dir <dir> option. When exporting realms to a directory, the server is going to create separate files for each realm being exported.

What database does Keycloak use?

Supported databases By default, the server uses the dev-file database. This is the default database that the server will use to persist data and only exists for development use-cases.


1 Answers

Go inside "Keycloak/bin/" folder and run below command to export all realms data.

sh standalone.sh -Dkeycloak.migration.action=export -Dkeycloak.migration.provider=singleFile -Dkeycloak.migration.file=keycloak-export.json -Djboss.http.port=8888 -Djboss.https.port=9999 -Djboss.management.http.port=7777

This will export everything but change ports which your using in "Standard.xml" file. Also, if you want to backup users as well, you can look into this guide:

https://github.com/slim-hmidi/keycloak-export-realm

Export your realm data and you can always take your postgres database backup or you can run cron job to take backup.

0 * * * 0 pg_dump -U postgres dbname > ~/postgres/backups/dbname.bak

like image 69
Mr Mayur Avatar answered Sep 20 '22 05:09

Mr Mayur