I have the following and needed help on getting this to work. I am unsure about the xml modification of sddraft syntax and order within the script. Any suggestions would be appreciated.
# ArcPy script to overwrite a published map document as a service via Server.
import xml.dom.minidom as DOM
# Set variables
mxd = r'sample.mxd'
server_con = 'ARCGIS_SERVER'
connection_file_path = r"GIS Servers\ARCGIS on xyz (publisher)"
service_name = "themap"
inFolderType = "EXISTING"
inFolder = "Test"
inStartup = "STARTED"
newType = 'esriServiceDefinitionType_Replacement'
# Set output path
sddraft = r'C:\Users\dunderwood\AppData\Local\ESRI\Desktop10.2\Staging\ARCGIS on GIS on xyz (publisher)\mapservice.sddraft'
sd_file = r'C:\Users\dunderwood\AppData\Local\ESRI\Desktop10.2\Staging\ARCGIS on GIS on xyz(publisher)\mapservice.sd'
# Method to create a SD file to overwrite an existing service
xml = sddraft
doc = DOM.parse(xml)
descriptions = doc.getElementsByTagName('Type')
for desc in descriptions:
if desc.parentNode.tagName == 'SVCManifest':
desc.firstChild.data = 'esriServiceDefinitionType_Replacement'
outXml = xml
f = open(outXml, 'w')
# 1 Create a service definition draft
analysis_result = arcpy.mapping.CreateMapSDDraft(mxd, sddraft)
print("SDdraft file created")
# 2 Stage and create Service Definition file
print("Service Definition file created")
# 3 Publish the SD file as a service
arcpy.UploadServiceDefinition_server(sd_file, connection_file_path, service_name,"#",inFolderType,inFolder,inStartup)
print("Service published successfully")