Last active
August 28, 2024 11:35
-
-
Save michaelknurr/a8f1941c6f40c0d784b1e467fbc694ba to your computer and use it in GitHub Desktop.
Revisions
-
michaelknurr revised this gist
Mar 28, 2018 . 1 changed file with 16 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,10 +19,23 @@ LOGFILE=/tmp/kc-$$.log rm -rf $KEYCLOAK_BACKUP_DIR $KEYCLOAK_HOME/bin/standalone.sh -Dkeycloak.migration.action=export -Dkeycloak.migration.provider=dir -Dkeycloak.migration.dir=$KEYCLOAK_BACKUP_DIR -Dkeycloak.migration.usersPerFile=500 -Djboss.socket.binding.port-offset=99 -Djboss.as.management.blocking.timeout=900 > $LOGFILE & sleep 5 KEYCLOAK_PID=$(ps -ef|grep java|grep "keycloak.migration.dir="|awk '{print $2}') SUCCESS="Export finished successfully" FAILURE="seconds waiting for service container stability. Operation will roll back" echo "Vorher: KEYCLOAK_PID=$KEYCLOAK_PID" while [ `grep "$SUCCESS" $LOGFILE | wc -l` == 0 ] ; do sleep 60 if [ `grep "$FAILURE" $LOGFILE | wc -l` != 0 ] ; then echo "killing keycloak with pid=$KEYCLOAK_PID"; kill $KEYCLOAK_PID; exit 1; fi; done kill $KEYCLOAK_PID # delete all files that have been modified more than 30 days ago find ~/archive/export -type f -mtime +30 -delete tar cfz ~/archive/export/keycloak-backup-$(date +%Y-%m-%d).tar.gz --remove-files -C $HOME keycloak-backup/* -
michaelknurr created this gist
Nov 10, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ #!/bin/bash # check, if another export is currently running if [ `ps -ef|grep "keycloak.migration.action=export" |grep -v grep |wc -l` != 0 ] ; then echo "Another export is currently running"; exit 1; fi # try to extract keycloak home from running keycloak instance KEYCLOAK_HOME=$(ps -ef|grep -v grep|grep jboss.home.dir|grep keycloak|sed 's/.*\(jboss.home.dir=\)//'|awk '{print $1}') # if this did not work, try to set other location if [ ! -x $KEYCLOAK_HOME ] ; then KEYCLOAK_HOME=/opt/keycloak fi KEYCLOAK_BACKUP_DIR=$HOME/keycloak-backup LOGFILE=/tmp/kc-$$.log rm -rf $KEYCLOAK_BACKUP_DIR $KEYCLOAK_HOME/bin/standalone.sh -Dkeycloak.migration.action=export -Dkeycloak.migration.provider=dir -Dkeycloak.migration.dir=$KEYCLOAK_BACKUP_DIR -Dkeycloak.migration.usersPerFile=500 -Djboss.socket.binding.port-offset=99 > $LOGFILE & while [ `grep "Export finished successfully" $LOGFILE | wc -l` == 0 ] ; do sleep 1; done KEYCLOAK_PID=$(ps -ef|grep java|grep "keycloak.migration.dir="|awk '{print $2}') kill $KEYCLOAK_PID