Python Script to backup only hosted feature layers AGOL / Enterprise

1938
2
01-11-2021 06:29 PM
ClintonBallandis1
Occasional Contributor

Hi,

Has anyone got a Python script that they are willing to share that only backs up hosted feature layers for either an AGOL organization or ArcGIS Enterprise Deployment. I'm only interested in backing up content that our users have created rather than any referenced feature services as these dataset are backed up via enterprise backups. 

I'm trying to remove the issue where users create hosted feature layers and rely on the data without taking manual backups. These users are unaware that AGOL hosted data can't be recovered or that you can't restore a datastore to get one hosted feature layer back.   

I've looked at running a notebook however we only have enterprise 10.7.1 so I can't see an easy way of scheduling this task either.

Any help would be appreciated

Thanks,

Clinton

2 Replies
by Anonymous User
Not applicable

You can use the ArcGIS Python API in regular python scripts outside of notebooks.  You still set it up with the

from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", "arcgis_python", "P@ssword123")

 and then use that gis object to find all the hosted files and make backups in the manner that suits your

items = gis.content.search('Palm Springs Trails')
for item in items:
    <get hosted layer id here with some legendary code>
gis.content.get('a0b157b9ce2440a39551967c7c789835')

and then set up the script in windows task manager or as a service.

I can search through some old code I have, but ESRI's examples are pretty good.

managing-your-content 

and you can install the API through conda:

https://developers.arcgis.com/python/guide/install-and-set-up/ 

DavidBlanchard
Esri Contributor

@Anonymous Userhas the right idea. I'll just add that once you've looped over an item that you want to backup, there functions like export (for GIS data), download (for files), and download_metadata that will help you save the content locally.