Solved! Go to Solution.
Rebecca Strauch, Emily Keefer-Cowles
Hello Rebecca, I am happy to note that you actually got this tool to work at your end. I am currently trying to use the tool to copy some bunch of map services from my existing ArcGIS Server 10.4 to a new ArcGIS Server 10.4 but I keep getting this error
Directory not copied. Error: [Error 3] The system cannot find the path specified: u'E\\arcgisserver\\directories\\arcgissystem\\arcgisinput\\NaturalResources\\MS4_Map_SupportingLayers_Public_Viewer_Natural_Resources.MapServer\\*.*'
Service MXD not found.
I don't understand why it is displaying the 'drive E' without the colon. Is this right?.
These are the paths I specified for the system sysTemp field
E:\arcgisserver\directories\arcgissystem\arcgisinput\sysTemp
for the backupTemp
E:\arcgisserver\directories\arcgissystem\arcgisinput\backup
Both 'sysTemp' and 'backup' folders were created in my new ArcGIS 10.4 Server which is the destination server. I didn't fill anything in the 'Destination_Folder' field
I have tried to follow all the steps you stipulated above unfortunately I'm still not able to get it to run successfully. Please can you explain more details of what exactly you did to get the tool to work for you.
I have over 280 map services I need to copy and would really be happy if this tool could work for me. That would make life much easier for me.
thanks
Hi Irene,
I was getting the same error, and I used arcpy.AddMessage or print statements to print out the variables and the approximate line number in my code (to I could find it easily). For my use, I used the V101 folder to grab my .mxd. I've included a snip of the code with my comments. I did several other changes after I resolved this, like read my admin credentials from an ini file vs hardcoding them, so my record numbers in my comments might be off.
...oops, need to open this in another browser tab to post my code...
Look at about line 76 below to see my comments
#...
else:
arcpy.AddMessage("\n ** Service '" + str(service) + "' information read successfully. Now transfering... (5 steps)")
# Deserialize response into Python object
propInitialService = json.loads(data)
user = getpass.getuser()
pathInitial = propInitialService["properties"]["filePath"]
#arcpy.AddMessage("pathInitial line 653: {0}".format(pathInitial))
pathInitial = pathInitial.replace(':', '$', 1) # this is stripping the ":" from d:\ with $
#arcpy.AddMessage("pathInitial line 655: {0}".format(pathInitial))
pathInitial = os.path.join("\\\\{0}".format(fromServerName), pathInitial) # add source server name to path
#arcpy.AddMessage("pathInitial line 657: {0}".format(pathInitial))
msdPath = pathInitial.replace('X', os.path.join(r'\\' + fromServerName, 'x'), 1)
#arcpy.AddMessage("msdPath line 659: {0}".format(msdPath))
if newFolder != "" : folderName = newFolder
else: folderName = os.path.split(service)[0]
serviceName = os.path.split(service)[1]
serviceName2 = serviceName
pos3 = serviceName2.find(".MapServer")
simpleServiceName = serviceName2[:pos3]
#arcpy.AddMessage("simpleServiceName line 668: {0}".format(simpleServiceName))
if folderName != 'root' or folderName != '':
finalServiceName = folderName + "//" + simpleServiceName + ".MapServer"
temp_workspace = string.replace(workspace, ':', '', 1)
temp_workspace = string.replace(temp_workspace, 'X', os.path.join(r'\\' + socket.gethostname(), 'x'), 1)
sources = os.path.join(temp_workspace, os.path.join(folderName, simpleServiceName + ".MapServer"))
else:
finalServiceName = serviceName
temp_workspace = string.replace(workspace, ':', '', 1)
sources = os.path.join(string.replace(temp_workspace, 'X', os.path.join(r'\\' + socket.gethostname(), 'x'), 1), serviceName)
#Check if the service exists
#arcpy.AddMessage("finalServiceName line 672: {0}".format(finalServiceName))
serviceExists = False
serviceExistsOld = False
serviceExists = isServicePresent(toServerName, str(toServerPort), targetServerToken, simpleServiceName, folderName, "")
pos = msdPath.find(serviceName) + len(serviceName)
#arcpy.AddMessage("pos line 687: {0}".format(pos))
inputFolderPath = msdPath[:pos]
#arcpy.AddMessage("inputFolderPath line 691: {0}".format(inputFolderPath))
inputFolderPath = os.path.join(inputFolderPath, "extracted", "v101")
#arcpy.AddMessage("inputFolderPath line 693: {0}".format(inputFolderPath))
#If service exists and must be overwritten
if serviceExists == True and overwrite == 'true':
#Backup old service
serviceURLforbackup = "/arcgis/admin/services/" + folderName + "/" + serviceName
#arcpy.AddMessage("\nserviceURLforbackup line 700: {0}".format(serviceURLforbackup))
# This request only needs the token and the response formatting parameter
tokenforbackup = targetServerToken # gentoken(toServerName, toServerPort, toAdminUser, toAdminPass)
paramsforbackup = urllib.urlencode({'token': tokenforbackup, 'f': 'json'})
responseforbackup, dataforbackup = postToServer(toServerName, str(toServerPort), serviceURLforbackup, paramsforbackup)
#arcpy.AddMessage("\nresponseforbackup line 706: {0}".format(responseforbackup))
#arcpy.AddMessage("\ndataforbackup line 707: {0}".format(dataforbackup))
if (responseforbackup.status == 200) and assertJsonSuccess(dataforbackup):
propInitialServiceforbackup = json.loads(dataforbackup)
pathInitialforbackup = propInitialServiceforbackup["properties"]["filePath"]
pathInitialforbackup = pathInitialforbackup.replace(':', '', 1)
msdPathforbackup = pathInitialforbackup.replace('X', os.path.join(r'\\' + toServerName, 'x'), 1)
#arcpy.AddMessage("\n msdPathforbackup line 715: {0}".format(msdPathforbackup))
posforbackup = msdPathforbackup.find(serviceName) + len(serviceName)
# doesn't handle the d$ or share correctly
# inputFolderPathforbackup = msdPathforbackup[:posforbackup]
# arcpy.AddMessage("\ninputFolderPathforbackup line 719: {0}".format(inputFolderPathforbackup))
# so using inputFolderPath which I modified above
#
copyFrom = inputFolderPath #inputFolderPathforbackup
#arcpy.AddMessage("\ncopyFrom line 722: {0}".format(copyFrom))
#
copyTo = os.path.join(workFolder, folderName, serviceName)
#arcpy.AddMessage("copyTo line 724: {0}".format(copyTo))
continuePublish1 = copy(copyFrom, copyTo)
continuePublish2 = createZipFile(copyFrom, workFolder + "\\" + folderName + "\\" + serviceName + ".zip")
if continuePublish1 == True and continuePublish2 == True:
arcpy.AddMessage(" Step 0: Old service backup done succesfully.")
else:
arcpy.AddMessage(" Step 0: Error when backing up old service .")
serviceExistsOld = serviceExists
serviceExists = False
Remember, the line numbers in the AddMessage statements won't match yours, but I suggest adding a few like this if you still need to trace things back. I left them in my code although, once fixed, I commented them out.
Hope this helps.
Thank you so much Rebecca, I did some modifications following the steps you described above, when I ran the script, it is able to copy over some of the map services and not able to copy some. It reported the error below which i believe could be specific to the individual map service. For these specific map services it is not able to analyze the service definition drafts and I am currently looking into this issue. Did you get similar error in yours?
Service could not be published because errors were found during analysis
Thank you very much
It looks like it's writing the errors to a text file:
...
# if the sddraft analysis contained errors
else:
#Service Definition Draft could not be analyzed
if analyseDraft['errors'] == "NO":
arcpy.AddWarning(" Service Definition Draft could not be analyzed.")
content = "\n " + formatDate() + "\n Service Definition Draft could not be analyzed. \n - " + finalServiceName + "\n"
serviceFailureNumber = serviceFailureNumber + 1
writeTxtFile(False, content, serviceFailureNumber, content1, workspace)
#writeInDatabase(fromServerName, toServerName, serviceType, finalServiceName, service, user, sources, 'Service Definition Draft could not be analyzed.')
else:
arcpy.AddWarning(" Service could not be published because errors were found during analysis. ")
content = "\n " + formatDate() + "\n Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n"
serviceFailureNumber = serviceFailureNumber + 1
writeTxtFile(False, content, serviceFailureNumber, content1, workspace)
You can add what's stored in the content variable to the AddWarning message:
...
# if the sddraft analysis contained errors
else:
#Service Definition Draft could not be analyzed
if analyseDraft['errors'] == "NO":
arcpy.AddWarning(" Service Definition Draft could not be analyzed.")
content = "\n " + formatDate() + "\n Service Definition Draft could not be analyzed. \n - " + finalServiceName + "\n"
serviceFailureNumber = serviceFailureNumber + 1
writeTxtFile(False, content, serviceFailureNumber, content1, workspace)
#writeInDatabase(fromServerName, toServerName, serviceType, finalServiceName, service, user, sources, 'Service Definition Draft could not be analyzed.')
else:
#Include the results of the analysis within the message
messageContent = "Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n"
#Add the message to the tool
arcpy.AddWarning(messageContent)
content = "\n " + formatDate() + "\n Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n"
serviceFailureNumber = serviceFailureNumber + 1
writeTxtFile(False, content, serviceFailureNumber, content1, workspace)
This way, it prints the message but also writes to the file created by the createTxtFile function, (whatever the "workspace" variable is defined to, which appears to be the sysTemp folder path).
Good point. I had forgotten about the log files. I do see one of my last tests I did have some failures, but more successes, listed in my logs. Some of them had that error. For me, I'll be able to review/analyze and fix and/or recreate them.
Irene....how many of the 280 gave you errors?
So far I tried to copy about 59 services at a time but it is only able to transfer 24 successfully while complaining that the remaining 23 services could not be transferred because errors were found during analysis.
When I analyzed some of the individual services it was having issues with, I noticed that there were some warning errors (not critical errors) like projection issues and so on. These are just warnings and not error.
I wonder why it wouldn't ignore those and go ahead and publish the maps just like ArcMap would do.
Jonathan Quinn wrote:
Jonathan Quinn wrote:
It looks like it's writing the errors to a text file:
... # if the sddraft analysis contained errors else: #Service Definition Draft could not be analyzed if analyseDraft['errors'] == "NO": arcpy.AddWarning(" Service Definition Draft could not be analyzed.") content = "\n " + formatDate() + "\n Service Definition Draft could not be analyzed. \n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace) #writeInDatabase(fromServerName, toServerName, serviceType, finalServiceName, service, user, sources, 'Service Definition Draft could not be analyzed.') else: arcpy.AddWarning(" Service could not be published because errors were found during analysis. ") content = "\n " + formatDate() + "\n Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace)
You can add what's stored in the content variable to the AddWarning message:
... # if the sddraft analysis contained errors else: #Service Definition Draft could not be analyzed if analyseDraft['errors'] == "NO": arcpy.AddWarning(" Service Definition Draft could not be analyzed.") content = "\n " + formatDate() + "\n Service Definition Draft could not be analyzed. \n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace) #writeInDatabase(fromServerName, toServerName, serviceType, finalServiceName, service, user, sources, 'Service Definition Draft could not be analyzed.') else: #Include the results of the analysis within the message messageContent = "Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n" #Add the message to the tool arcpy.AddWarning(messageContent) content = "\n " + formatDate() + "\n Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace)
This way, it prints the message but also writes to the file created by the createTxtFile function, (whatever the "workspace" variable is defined to, which appears to be the sysTemp folder path).
It looks like it's writing the errors to a text file:
... # if the sddraft analysis contained errors else: #Service Definition Draft could not be analyzed if analyseDraft['errors'] == "NO": arcpy.AddWarning(" Service Definition Draft could not be analyzed.") content = "\n " + formatDate() + "\n Service Definition Draft could not be analyzed. \n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace) #writeInDatabase(fromServerName, toServerName, serviceType, finalServiceName, service, user, sources, 'Service Definition Draft could not be analyzed.') else: arcpy.AddWarning(" Service could not be published because errors were found during analysis. ") content = "\n " + formatDate() + "\n Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace)
You can add what's stored in the content variable to the AddWarning message:
... # if the sddraft analysis contained errors else: #Service Definition Draft could not be analyzed if analyseDraft['errors'] == "NO": arcpy.AddWarning(" Service Definition Draft could not be analyzed.") content = "\n " + formatDate() + "\n Service Definition Draft could not be analyzed. \n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace) #writeInDatabase(fromServerName, toServerName, serviceType, finalServiceName, service, user, sources, 'Service Definition Draft could not be analyzed.') else: #Include the results of the analysis within the message messageContent = "Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n" #Add the message to the tool arcpy.AddWarning(messageContent) content = "\n " + formatDate() + "\n Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace)
This way, it prints the message but also writes to the file created by the createTxtFile function, (whatever the "workspace" variable is defined to, which appears to be the sysTemp folder path).
Jonathan Quinn wrote:
It looks like it's writing the errors to a text file:
... # if the sddraft analysis contained errors else: #Service Definition Draft could not be analyzed if analyseDraft['errors'] == "NO": arcpy.AddWarning(" Service Definition Draft could not be analyzed.") content = "\n " + formatDate() + "\n Service Definition Draft could not be analyzed. \n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace) #writeInDatabase(fromServerName, toServerName, serviceType, finalServiceName, service, user, sources, 'Service Definition Draft could not be analyzed.') else: arcpy.AddWarning(" Service could not be published because errors were found during analysis. ") content = "\n " + formatDate() + "\n Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace)
You can add what's stored in the content variable to the AddWarning message:
... # if the sddraft analysis contained errors else: #Service Definition Draft could not be analyzed if analyseDraft['errors'] == "NO": arcpy.AddWarning(" Service Definition Draft could not be analyzed.") content = "\n " + formatDate() + "\n Service Definition Draft could not be analyzed. \n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace) #writeInDatabase(fromServerName, toServerName, serviceType, finalServiceName, service, user, sources, 'Service Definition Draft could not be analyzed.') else: #Include the results of the analysis within the message messageContent = "Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n" #Add the message to the tool arcpy.AddWarning(messageContent) content = "\n " + formatDate() + "\n Service could not be published because errors were found during analysis. \n " + str(analyseDraft['errors']) + "\n - " + finalServiceName + "\n" serviceFailureNumber = serviceFailureNumber + 1 writeTxtFile(False, content, serviceFailureNumber, content1, workspace)
This way, it prints the message but also writes to the file created by the createTxtFile function, (whatever the "workspace" variable is defined to, which appears to be the sysTemp folder path).
Hi Jonathan,
I have tried to include your suggestion above to my script but its not making any difference to the output. I'm just wondering how I can instruct the script to ignore
the non-critical errors in the Analysis stage and proceed to publish the service.
Some of the errors include discrepancy in the map projection, layer draws at all scale etc.
Is there a way to tell the script to bypass some of these non critical errors and publish the service
--inputFolderPath line 691: \\Hamiltonpool\E$\arcgisserver\directories\arcgissystem\arcgisinput\NaturalResources\MS4_Viewer_RegBoundaries.MapServer
inputFolderPath line 693: \\Hamiltonpool\E$\arcgisserver\directories\arcgissystem\arcgisinput\NaturalResources\MS4_Viewer_RegBoundaries.MapServer\extracted\v101
Step 1: Creating Service Definition Draft (.sddraft)
Step 2: Analyzing Service Definition Draft.
The following information was returned during analysis of the MXD:
MESSAGES:
Service could not be published because errors were found during analysis
Since it's going into the else block, (line 777 in the original script on github), what I would do is print the results of the analysis:
Ex.
arcpy.AddMessage(analyseDraft)
This is a simple way to see why it's reaching that else block. It looks like the analyseServiceDraft is already going through the messages within the analysis starting on lines 1178, so from your output, it doesn't seem like there are any error messages.
def analyseServiceDraft(draftXml, service):
analysis = {}
try:
# Analyze the service definition draft
analysis = arcpy.mapping.AnalyzeForSD(draftXml)
# Print errors, warnings, and messages returned from the analysis
count = 0
mess = " The following information was returned during analysis of the MXD: "
for key in ('messages', 'warnings', 'errors'):
mess = mess + "\n " + key.upper() + ":"
vars = analysis[key]
mess2 = ""
for ((message, code), layerlist) in vars.iteritems():
mess2 = mess2 + "\n - " + message + " (CODE %i)" % code
mess2 = mess2 + " applies to:"
for layer in layerlist:
count = count + 1
mess2 = mess2 + "\n " + str(count) + " : "+ layer.name
mess = mess + mess2
if analysis['errors'] != {}:
analysis['errors'] = mess
arcpy.AddMessage(mess)
return analysis
# if the sddraft analysis fails
except:
#Service Definition Draft could not be analyzed
analysis['errors'] = "NO"
return analysis
inputFolderPath line
691: \\Hamipool\E$\arcgisserver\directories\arcgissystem\arcgisinput\Public\Bike_Safety_Committee_Project.M...
inputFolderPath line
693:Hamipool\E$\arcgisserver\directories\arcgissystem\arcgisinput\Public\Bike_Safety_Committee_Project.MapServer\extracted\v101
Step 1: Creating Service Definition Draft (.sddraft)
Step 2: Analyzing Service Definition Draft.
The following information was returned during analysis of the MXD:
MESSAGES:
- Layer draws at all scale ranges (CODE 30003) applies to: Is this supposed to be a critical problem
1 : Commissioner Precincts
2 : Public Schools
3 : Bike Safety Committee Recommendations 2013
4 : Existing Bike Routes
5 : CoA's OCG Trail (Built)
6 : Travis County Park Trails
7 : County Maintained Roads
8 : County Rds by Treatment Types
9 : County Rds by Condition
10 : Corridors_TNRs
11 : CAMPO 2035 Plan
12 : Travis_County_Parks
13 : LCRA_Parks_All
14 : COA_Parks_All
15 : Other_Juris_Parkland_All
16 : State_Parks_All
17 : City Limits
18 : ETJs
19 : County_Boundary_Line
Service could not be published because errors were found during analysis.
In some cases it doesn’t even return any message
Step 1: Creating Service Definition Draft (.sddraft)
Step 2: Analyzing Service Definition Draft.
The following information was returned during analysis of the MXD:
MESSAGES:
Service could not be published because errors were found during analysis.
Irene Egbulefu I edited your last response so it didn't include my previous response, quoted, twice. But it doesn't look like your error message got pasted. you may want to try again. oh, never mind...the green was the error message.
I do not have anywhere the number of services you have to move over, but it won't surprise me if all mine do not come over cleanly either. Keep in mind that I made sure my data was copied over to the new server, if needed, and made sure all my data links were also set up exactly the same, that is,same names. My guess is that is there is anything that is "broken" in the source service, it will have issues copying over.