DevOPS Script to export 12c OSB projects/components using Python and Shell Script
Create below three files in any location of your Fusion LPAR:
- export.properties
- export.py
- export.sh
Run your shell script with command ./export.sh and the export with date and time stamp will be created in /backup/$LOGNAME location. Please change the location of the export in export.sh
Content of each script is as follows:
export.properties –
adminUrl=<http://localhost:portnumber/sbconsole>
exportUser=weblogic
exportPassword=<weblogic_password>
exportJar=sbexport.jar
NOTE: Please define your Admin URL and weblogic password in the above script
Food For Thought: One can also use tokenisation for Admin URL and/or weblogic password in the above script
export.py –
from java.io import FileInputStream
from java.io import FileOutputStream
from java.util import ArrayList
from java.util import Collections
from java.util import HashMap
from java.util import HashSet
from com.bea.wli.sb.util import EnvValueTypes
from com.bea.wli.config.env import EnvValueQuery;
from com.bea.wli.config import Ref
from com.bea.wli.config.customization import Customization
from com.bea.wli.config.customization import FindAndReplaceCustomization
import sys
def exportAll(exportConfigFile):
try:
print “Loading export config from :”, exportConfigFile
exportConfigProp = loadProps(exportConfigFile)
adminUrl = exportConfigProp.get(“adminUrl”)
exportUser = exportConfigProp.get(“exportUser”)
exportPasswd = exportConfigProp.get(“exportPassword”)
exportJar = exportConfigProp.get(“exportJar”)
customFile = exportConfigProp.get(“customizationFile”)
passphrase = exportConfigProp.get(“passphrase”)
project = exportConfigProp.get(“project”)
connectToServer(exportUser,exportPasswd,adminUrl)
ALSBConfigurationMBean = findService(“ALSBConfiguration”, “com.bea.wli.sb.management.configuration.ALSBConfigurationMBean”)
print “ALSBConfiguration MBean found”
print “Input project: “, project
if project == None :
ref = Ref.DOMAIN
collection = Collections.singleton(ref)
if passphrase == None :
print “Export the config”
theBytes = ALSBConfigurationMBean.export(collection, true, None)
else :
print “Export and encrypt the config”
theBytes = ALSBConfigurationMBean.export(collection, true, passphrase)
else :
ref = Ref.makeProjectRef(project);
print “Export the project”,project
collection = Collections.singleton(ref)
theBytes = ALSBConfigurationMBean.exportProjects(collection, passphrase)
aFile = File(exportJar)
out = FileOutputStream(aFile)
out.write(theBytes)
out.close()
print “ALSB Configuration file: “+ exportJar + ” has been exported”
except:
raise
def loadProps(configPropFile):
propInputStream = FileInputStream(configPropFile)
configProps = Properties()
configProps.load(propInputStream)
return configProps
def connectToServer(username,password,url):
connect(username,password,url)
domainRuntime()
try:
exportAll(sys.argv[1])
except:
print “Unexpected error: “, sys.exc_info()[0]
dumpStack()
raise
export.sh –
export S_ADMIN_URL=`grep ADMIN_URL ${HOME}/context/environ.ref | awk -F = ‘{print $2}’`
export S_WL_PASS=$(${Build_Path}/Scripts/sse_stp_getpass.sh WL)
export jca_file_list=$(find ${Build_Path}/Scripts -name export.properties | sed ‘s/ /*/g’)
print “\n\n++++ Starting Tokenisation of the properties file ++++\n\n”
for line in $jca_file_list; do
print “\n == Tokenising $line == \n”;
OLDIFS=”$IFS” # save it
IFS=”” # don’t split on any white space
jca_file=$line
jca_file_original=$line.original
cp $jca_file $jca_file_original
if (grep _WL $jca_file)
then
sed “s/_WL/$S_WL_PASS/g” $jca_file > $jca_file.tmp
mv $jca_file.tmp $jca_file
print ” Tokenised Values:”
print ” Token Name = _WL and Token Value = *****”
fi
while read token
do
if [[ “$token” == *=* ]];
then
export token_name=_$(echo $token | awk -F = ‘{print $1}’); export token_value=$(echo $token | awk -F = ‘{print $2}’ | sed ‘s/\//\\\//g’);
if (grep $token_name $jca_file)
then
sed “s/$token_name/$token_value/g” $jca_file > $jca_file.tmp
mv $jca_file.tmp $jca_file
print ” Tokenised Values:”
print ” Token Name = $token_name and Token Value = $token_value”
fi
fi
done < ${HOME}/context/environ.ref
chmod 755 $jca_file
done
cd ${OSB_HOME}/tools/configjar
. ./setenv.sh
cd ${Build_Path}/Scripts
java weblogic.WLST export.py export.properties
mv sbexport.jar /backup/$LOGNAME/sbexport_$(date ‘+%d%m%Y_%H%M%S’).jar

Very useful post
LikeLike
changes few configuration and was really useful for automatic export of OSB.
LikeLike
Very informative post
LikeLike
Thanks for sharing the automation process. Very useful one.
LikeLike
Great content!
LikeLiked by 1 person
Great article..very detailed and straightforward
LikeLike
Nicely explained
LikeLike
Very useful content
LikeLiked by 1 person
Very useful post
LikeLike
Thanks very useful
LikeLike
Very informative and easy to understand!!
LikeLike
Very useful content on OSB project Automation
LikeLiked by 1 person
Useful article !!
LikeLike
Useful
LikeLike
Informative. Keep up the good work
LikeLike
Brilliant!
LikeLike
Well explained
LikeLike