Skip to content

Instantly share code, notes, and snippets.

@bwright2810
Last active February 16, 2019 10:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwright2810/37d7d9d8e0e8e3d6d5fa15d82e4dd8ef to your computer and use it in GitHub Desktop.
Save bwright2810/37d7d9d8e0e8e3d6d5fa15d82e4dd8ef to your computer and use it in GitHub Desktop.
Python 2 Script for copying Websphere profiles (verified with WAS 8.5) (see https://stackoverflow.com/questions/17525260/how-to-clone-a-websphere-8-profile)
import sys
import shutil
import xmltodict
import os
def main():
wasRoot = "C:/ibm/WebSphere855/AppServer"
oldProf = "AppSrv03"
newProf = "AppSrv06"
profDir = wasRoot + "/profiles"
print "Copying old profile"
shutil.copytree(profDir + "/" + oldProf, profDir + "/" + newProf)
print "Adjusting setupCmdLine.bat"
setupCmdLinePath = profDir + "/" + newProf + "/bin/setupCmdLine.bat"
replaceProfileNameInFile(setupCmdLinePath, oldProf, newProf)
print "Adjusting ssl.client.props"
sslClientPropsPath = profDir + "/" + newProf + "/properties/ssl.client.props"
replaceProfileNameInFile(sslClientPropsPath, oldProf, newProf)
print "Adjusting firststeps.bat"
firststepsPath = profDir + "/" + newProf + "/firststeps/firststeps.bat"
replaceProfileNameInFile(firststepsPath, oldProf, newProf)
print "Add profile to profileRegistry.xml"
profilesXmlPath = wasRoot + "/properties/profileRegistry.xml"
with open(profilesXmlPath, 'r') as f:
xml = xmltodict.parse(f.read())
profilesXml = xml['profiles']['profile']
newProfDict = profilesXml[0].copy()
newProfDict['@name'] = newProf
newProfDict['@path'] = profDir + '/' + newProf
newProfDict['@template'] = wasRoot + '/profileTemplates/default'
newProfDict['@isDefault'] = 'false'
profilesXml.append(newProfDict)
with open(profilesXmlPath, 'w') as f:
f.write(xmltodict.unparse(xml))
cell = os.listdir(profDir + '/' + newProf + '/config/cells')[0]
node = os.listdir(profDir + '/' + newProf + '/config/cells/' + cell + '/nodes')[0]
print "Adjusting variables.xml for cell %s, node %s" % (cell, node)
variablesPath = profDir + '/' + newProf + '/config/cells/' + cell + '/nodes/' + node + "/variables.xml"
replaceProfileNameInFile(variablesPath, oldProf, newProf)
print "Copying and adjusting " + oldProf + ".bat"
oldProfileBatPath = wasRoot + "/properties/fsdb/" + oldProf + ".bat"
newProfileBatPath = oldProfileBatPath.replace(oldProf, newProf)
shutil.copyfile(oldProfileBatPath, newProfileBatPath)
replaceProfileNameInFile(newProfileBatPath, oldProf, newProf)
print "Profile %s successfully copied to %s" % (oldProf, newProf)
def replaceProfileNameInFile(filepath, oldProf, newProf):
with open(filepath, 'r') as f:
fileContents = f.read()
newFileContents = fileContents.replace(oldProf, newProf)
with open(filepath, 'w') as f:
f.write(newFileContents)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment