Select to view content in your preferred language

Output name oddity using FeatureClassToGeodatabase to copy hosted feature layers in AGO

09-01-2023 09:44 AM
New Contributor II


So I'm working on a python script to back up hosted feature layers in AGO to a local file geodatabase.

I'm aware of this one on ESRI's knowledge-base, but it's a little more broad than I'm really looking for. And I'm trying to develop something that's friendly for people who aren't as familiar with python (or scripting in general). Idea being that someone can just add a layer to the map and it'll get included in the back up and you don't have to worry about getting tags, categories, or ownership stuff set up. Best practice aside, that's that reality.

Here's the script I'm running and it works but I sometimes get an odd output for the feature class names like "GPLYR - [GlobalID looking string]" (see snip below the code).

# Set the Pro project (.aprx) that contains the layers you want to share/publish.
prj ='Current') # Set, uses this aprx
mp = prj.listMaps("Storm Damage Assessment")[0] 
lyrlist = mp.listLayers()

# Set output locations and name
outdir = r"C:\GIS Data" # SET, where should the file geodatabase and feature classes go?
fgdbname = r"Storm Damage Assessment" # SET, name the new file geodatabase to be created.

# Date/time
date = time.strftime("%Y%m%d")

AGOBackupfgdb =, fgdbname + "_" + date)
#AGOBackuppath = os.path.join(outdir, fgdbname + "_" + date + ".gdb")

      for lyr in lyrlist:
            print ("Exporting " +
             #arcpy.conversion.ExportFeatures(lyrL, AGOBackuppath + "\\" +
             print("\t Success")
       print("Failed to export to file geodatabase.")


I've also written another version of the script that loops through all the maps in the Pro Project to copy the hosted feature layers to file geodatabase (one per map). Usually one of the back up sets of hosted feature layers has the correct names but the others have that GPLYR name for the feature class.

     for m in mp:
            print("Backing up layers from " +
            lyrlist = m.listLayers()
            AGOBackupfgdb =, + "_" + date)
            lyrlist = m.listLayers()
           for lyr in lyrlist:
                print ("\t" +
                print("\t Done \n")
                print("Successfully backed up layers")

Maybe FeatureClasstoGeodatabase isn't the best method? I'm trying to use ExportFeatures, but for whatever reason I cannot get it to work. It looks like there are some parameters from FeatureClasstoFeatureClass that didn't get carried over to ExportFeatures when it get deprecated.

Thank you for any help or input on improving the script methodology or why some feature classes are getting named GPLYR and how to solve it.


0 Kudos
3 Replies
MVP Notable Contributor

Not sure where that is coming from, but I use a modified version of the link you provided.

Once connected, you can query by Hosted Feature Service name rather than worrying about tags, ownership, etc.

query_string =  f"type:Feature Service, title:SSA_Map_Data"

But will backup the entire HFS, not just individual layers.

In case it helps,


New Contributor

Does anyone else get the error below when arcpy.conversion.ExportFeatures(x,y,"alias"...) is ran?
AttributeError: 'module' object has no attribute 'ExportFeatures'

0 Kudos
MVP Notable Contributor

If I try to run it in Pro 2.x I get that error as it doesn't appear as if it was added until Pro 3.