Here’s a simple Shell script to backup an OpenAM server. Feel free to customize it, for example if you use an external configuration store.

This script will:

– backup the OpenAM bootstrap file

– export the OpenAM configuration in XML format

– export the OpenAM embedded configuration directory in LDIF format

– create a tar archive of the OpenAM configuration directory

#!/bin/sh
ADMIN_PWD='password'
AM_ENC_KEY=bwl6/345BGDDRkRokuTFhCfCAlSkghKw9f9u
BACKUP_DIR=/opt/depot/backup
DEPLOYMENT_URI=/openam
JAVA_HOME=/usr/java/default
SERVER_URL=https://openam.sub.domain:8780
SERVICE=tomcat
TOMCAT_USER=tomcat
TOOLS_DIR=/opt/openam-tools

export ADMIN_PWD AM_ENC_KEY BACKUP_DIR DEPLOYMENT_URI JAVA_HOME SERVER_URL SERVICE TOMCAT_USER TOOLS_DIR



# OpenAM configuration backup
OpenAM_Backup()
{
echo
echo Backing up OpenAM ...

echo -n $ADMIN_PWD > /tmp/amadmin_password
chown $TOMCAT_USER /tmp/amadmin_password $BACKUP_DIR
chmod 400 /tmp/amadmin_password


# Service configuration backup
su $TOMCAT_USER -c "export LC_MESSAGES=en_US && export JAVA_HOME=$JAVA_HOME && $TOOLS_DIR$DEPLOYMENT_URI/bin/ssoadm export-svc-cfg --encryptsecret $AM_ENC_KEY --outfile $BACKUP_DIR/conf-service.xml --adminid amadmin --password-file /tmp/amadmin_password"

if [ $? -eq 0 ] ; then
 echo OpenAM service configuration exported.
else
 echo Problem while trying to export the OpenAM configuration in XML !
fi
echo


rm -f /tmp/amadmin_password


# OpenAM bootstrap file backup
echo
su - $TOMCAT_USER -c "cp ~/.openamcfg/AMConfig_*_webapps_$URI\"_\" $BACKUP_DIR"
if [ $? -eq 0 ] ; then
 echo Bootstrap file saved.
else
 echo Problem while trying to save OpenAM bootstrap file !
fi
echo

# Configuration directory backup
Tomcat_Stop $1
pushd $BASE_DIR >/dev/null
su $TOMCAT_USER -c "tar cf $BACKUP_DIR/conf-$URI.tar . --exclude=./opensso/log/* --exclude=./opensso/debug/* --exclude=./opends/logs/* --exclude=./OpenAMTools/ssoAdminTools/log/* --exclude=./OpenAMTools/ssoAdminTools/debug/*"
if [ $? -eq 0 ] ; then
 echo OpenAM configuration directory archived.
else
 echo Problem while backing up OpenAM configuration directory !
fi
echo

# OpenAM configuration datastore export
pushd opends/bin >/dev/null
su $TOMCAT_USER -c "./export-ldif -l $BACKUP_DIR/openam-configstore.ldif -n userRoot"
if [ $? -eq 0 ] ; then
 echo OpenAM configuration datastore exported.
else
 echo Problem while exporting OpenAM configuration datastore !
fi
echo

popd >/dev/null #return from OpenDS subdir
popd >/dev/null #return from OpenAM configuration directory
Tomcat_Start $1
}


Tomcat_Stop()
{
/etc/init.d/$SERVICE stop $1 2>/dev/null

proc=$($JAVA_HOME/bin/jps -v|grep Bootstrap|grep $TOMCAT_USER |awk '{print $1}')

while [ $proc ]
 do
 sleep 2
 #sudo /bin/kill -TERM $proc 2>/dev/null
 echo Waiting for Tomcat to stop ...
 proc=$($JAVA_HOME/bin/jps -v|grep Bootstrap|grep tomcat|awk '{print $1}')
 done
echo
}


Tomcat_Start()
{
/etc/init.d/$SERVICE start

var_http_code=0
while [ $var_http_code != 200 ]; do sleep 2 ; var_http_code=$(curl -o /dev/null -f -s -w "%{http_code}" -k "$SERVER_URL$DEPLOYMENT_URI/isAlive.jsp") ; echo "Waiting for Tomcat to start ..." ; done
echo
}


# Main program
URI=$(echo $DEPLOYMENT_URI |cut -d / -f 2)
BASE_DIR=`su - $TOMCAT_USER -c "cat ~/.openamcfg/AMConfig_*_webapps_$URI\"_\""`
export BASE_DIR URI

OpenAM_Backup $DEPLOYMENT_URI
Les derniers articles par janua (tout voir)