Arcgis Pro - OVERWRITE existing Standalone Service with python

681
2
07-15-2020 08:30 AM
jonathanharte
New Contributor III

arcgis pros1

Arcgis Pro - OVERWRITE existing Standalone Service using python The current process in Arcgis Pro (Manual Only)

I have and existing service published to standalone Arcgis server 10.6 that is cached, and I want to automate an Overwrite process that retains the cache but replaces the base data I use for popups.  I've been doing this for years and its simple in arcmap ... Its also simple in Arcgis Pro if I right click on the service and use the Overwrite function - but I need to automate in notebook this but there does not appear to be anything in python to do this .. Or have I missed a  process?  

I have followed some threads with various leads .. but so far I have been unsuccessful...   I can create a sddraft and an sd for the service with the new content - but when I try UpLoadServiceDefniition .. it fails with service already exists but I cannot seem to find any switch to allow it overwrite ?

In the future I will be doing this with hosted features on my portal - but for the moment this is not an option for me. 

Any pointers would be hugely helpful please...  my efforts so far have not been successful.

Regards

Paulg

Tags (2)
0 Kudos
2 Replies
KoryKramer
Esri Community Moderator

Have you read through https://community.esri.com/thread/216491-automate-overwrite-web-layer-feature-class and tried the example(s) provided?

0 Kudos
Arne_Gelfert
Occasional Contributor III

Following the general 3-step process I've seen in so many ESRI examples - Draft-Stage-Upload, the overwriting puzzled me until I added the line high lighted below:

# Create MapImageSharingDraft and set service properties
sharing_draft = m.getWebLayerSharingDraft("FEDERATED_SERVER", "MAP_IMAGE", service)
...
##############################################################################
#The following line governs whether the new draft is used to overwrite the existing services
sharing_draft.overwriteExistingService = True
##############################################################################
...
sharing_draft.exportToSDDraft(sddraft_output_filename)
    
# Stage Service
..
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)
# Share to portal
arcpy.UploadServiceDefinition_server(inSdFile, inServer, inServiceName,inCluster, inFolderType, inFolder, inStartup, inOverride, inMyContents, inPublic, ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

The exact details may be different in your environment.That's why I've stripped it down.