HOW TO
This script uses ArcGIS API for Python to back up hosted feature layers in an ArcGIS Online organization by exporting each hosted feature service to a file geodatabase and downloading it to a specified local output folder.
Note: This script must be run in an ArcGIS Notebook in ArcGIS Pro because it downloads items to the machine’s local file system. Notebooks in ArcGIS Online run in an isolated hosted container and cannot write directly to local paths.
from arcgis.gis import GIS import os
gis = GIS("https://www.arcgis.com", "username", "password")
output_folder = r""
hosted_feature_layers = gis.content.search(query=f'type:"Feature Service"', max_items=-1)
for myLayer in hosted_feature_layers:
print(f"Title:{myLayer.title}, Item ID:{myLayer.id}, Owner:{myLayer.owner}, ItemType:{myLayer.type}" )
for layer in hosted_feature_layers:
try:
export_layer = layer.export(layer.title, "File Geodatabase")
export_layer.download(save_path=output_folder)
print(f"Downloaded: {layer.title}")
except Exception as e:
print(f"Failed for {layer.title}: {e}")
Article ID: 000040505
Get help from ArcGIS experts
Start chatting now