<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to create Hosted feature layer backups periodically in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1419453#M59062</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;How do you recommend to run periodical backups from a hosted feature layer ?&lt;/P&gt;&lt;P&gt;Several layers are editing a group of layers and we need to make backups.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 May 2024 15:49:15 GMT</pubDate>
    <dc:creator>JoseSanchez</dc:creator>
    <dc:date>2024-05-06T15:49:15Z</dc:date>
    <item>
      <title>How to create Hosted feature layer backups periodically</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1419453#M59062</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;How do you recommend to run periodical backups from a hosted feature layer ?&lt;/P&gt;&lt;P&gt;Several layers are editing a group of layers and we need to make backups.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 15:49:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1419453#M59062</guid>
      <dc:creator>JoseSanchez</dc:creator>
      <dc:date>2024-05-06T15:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Hosted feature layer backups periodically</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1419497#M59065</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Geodatabase Backups&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I recommend adding a Tag to any content you want to backup.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_Laue_0-1715013689755.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103231iB4AAAA2CE7F0237D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_Laue_0-1715013689755.png" alt="Tom_Laue_0-1715013689755.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then via Python script, you can download any content with that Tag to gdb and schedule the script (via Task Scheduler) to run daily or weekly as you need.&lt;BR /&gt;&lt;BR /&gt;I use the tag:&amp;nbsp;&lt;STRONG&gt;GDBNightlyBackup&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import datetime
startTime = datetime.datetime.now()
TodaysDate = datetime.date.today().isoformat()
print (startTime)
##############

import arcgis
from arcgis.gis import GIS
import os

#enter AGOL sign-in credentials
gis = GIS("https://yourorg.maps.arcgis.com", "username", "password",verify_cert=False)



now = datetime.datetime.now()
folderName = now.strftime("%Y-%m-%d")
#print (folderName)
parent_dir = r"C:\ArcGISOnline\BackupFiles\FeatureLayers"
path = os.path.join(parent_dir, folderName)

#create folder if it doesn't exist
if os.path.isdir(path):
    pass
else:
    os.mkdir(path)
    print("Directory '% s' created" % folderName)
    

def downloadItems(downloadFormat):
    try:
        download_items = [i for i in gis.content.search(query="tags: = 'GDBNightlyBackup'", item_type='Feature Layer', 
                     max_items=-1)]
        #print(download_items)
        # Loop through each item and if equal to Feature service then download it
        for item in download_items:
            if item.type == 'Feature Service':
                print(item)
                result = item.export(f'{item.title}', downloadFormat)
                #r'file path of where to store the download'
                result.download(path)
                # Delete the item after it downloads to save on space
                result.delete()
    except Exception as e:
        print(e)

downloadItems(downloadFormat='File Geodatabase')


#############
    
endTime = datetime.datetime.now()
td = endTime - startTime
hours, remainder = divmod(td.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
TimeElapsed='{:02}:{:02}:{:02}'.format(int(hours), int(minutes), int(seconds))

print ("")
print ("Done!")
print ("")
print ("Ended at " + str(endTime))
print ("Time elapsed " + str(td)) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result is I have backup folders every day for all the hosted content I've been downloading.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_Laue_1-1715013789245.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103232iC74E0A3043A13B83/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_Laue_1-1715013789245.png" alt="Tom_Laue_1-1715013789245.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 16:49:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1419497#M59065</guid>
      <dc:creator>Tom_Laue</dc:creator>
      <dc:date>2024-05-06T16:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Hosted feature layer backups periodically</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1419506#M59066</link>
      <description>&lt;P&gt;&lt;STRONG&gt;JSON backups&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly, I also backup the content JSON files incase schema on a hosted layer gets changed or a webmap/dashboard/app gets inadvertently changed or broken.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ESRI webmaps, dashboards, etc. have two parts to their JSON data.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Description&lt;/LI&gt;&lt;LI&gt;Data&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Data is where all the customizations you’ve made to the content are stored.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_Laue_2-1715013978834.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103234iB6A54B3562F553ED/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_Laue_2-1715013978834.png" alt="Tom_Laue_2-1715013978834.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The script is set to download all the following JSON Data for the following item types in your Portal:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Web Map&lt;/LI&gt;&lt;LI&gt;Web Mapping Application&lt;/LI&gt;&lt;LI&gt;Feature Layer&lt;/LI&gt;&lt;LI&gt;Application&lt;/LI&gt;&lt;LI&gt;Dashboard&lt;/LI&gt;&lt;LI&gt;Web Experience&lt;/LI&gt;&lt;LI&gt;item_types&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_Laue_3-1715013978836.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103233i5203D2D82FC3141C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_Laue_3-1715013978836.png" alt="Tom_Laue_3-1715013978836.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If a new item of that type is added to Portal, a new folder is created from the item name.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_Laue_4-1715013978843.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103235iCC529AB7022C80CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_Laue_4-1715013978843.png" alt="Tom_Laue_4-1715013978843.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the content was modified in the last 24 hours, a new JSON file is saved.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_Laue_5-1715013978847.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/103236i96A14B6C0C77FE1D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_Laue_5-1715013978847.png" alt="Tom_Laue_5-1715013978847.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcgis
from arcgis import gis
from arcgis.gis import GIS
import json
import os
import glob

gis = arcgis.gis.GIS("https://yourorg.maps.arcgis.com", "username", "password")

import datetime
now = datetime.datetime.now()
dateString = now.strftime("%Y-%m-%d")


folder_location = r"C:\ArcGISOnline\BackupFiles\JSON"

item_types = { 'Web Map',  'Web Mapping Application',  'Feature Layer','Application', 'Dashboard', 'Web Experience'}




for itemType in item_types:

    folder_name = itemType
    subfolder_path = os.path.join(folder_location,folder_name)
    try:
        os.mkdir(subfolder_path)
    except:
        pass

    print("\n"+itemType)
    itemType_items = gis.content.search(query="*",item_type=itemType,max_items=10000)


    
    listOfItemIDs = []
    for item in itemType_items:
        listOfItemIDs.append(item.id)

    for iid in listOfItemIDs:
        my_item = gis.content.get(iid)
        
        item_title = my_item.title
        removestring ="%:/,.\\[]&amp;lt;&amp;gt;*?$"
        item_title = ''.join([c for c in item_title if c not in removestring]).strip()
        

        file_name = item_title+"_"+itemType+"_"+str(dateString)+".json"
        file_path_item_folder = os.path.join(subfolder_path ,item_title)
        file_path = os.path.join(file_path_item_folder ,file_name)

        item = my_item.get_data(try_json=True)

        if len(item)&amp;gt;0: # only proceed if json dump is not empty
            
            try:
                #print(file_path_item_folder)
                os.mkdir(file_path_item_folder)
            except:
               a=1 


            full_path = os.path.join(file_path_item_folder,file_name)

            #get date of newest file in folder
            list_of_files = glob.glob(file_path_item_folder+"\*")

            if len(list_of_files)&amp;gt;0:    
                latest_file = max(list_of_files, key=os.path.getctime)
                newestFileDate = os.path.getmtime(latest_file )
            else:
                newestFileDate = 0
                        


            #note:  does not run on empty folders with no json exports already
            if newestFileDate == 0 or my_item.modified/1000&amp;gt;newestFileDate   : # if modified date newer than last json or no json in folder
                print("\t"+item_title)
                print(full_path)
                with open (full_path, "w") as file_handle:
                    file_handle.write(json.dumps(item))
        
print("\n\nCompleted")


&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 16:48:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1419506#M59066</guid>
      <dc:creator>Tom_Laue</dc:creator>
      <dc:date>2024-05-06T16:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Hosted feature layer backups periodically</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1559561#M62436</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/299157"&gt;@Tom_Laue&lt;/a&gt;&amp;nbsp;thanks for sharing this script.&lt;/P&gt;&lt;P&gt;What would be the process to restore the content if needs be?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Hanlie&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 08:20:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1559561#M62436</guid>
      <dc:creator>HanliePetoors</dc:creator>
      <dc:date>2024-11-18T08:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Hosted feature layer backups periodically</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1559803#M62441</link>
      <description>&lt;P&gt;Hi Hanlie,&lt;BR /&gt;&lt;BR /&gt;As far as restoring an item from JSON if you accidentally deleted it or if I just want to compare the current vs backed-up item, I create a brand new webmap or dashboard manually in Chrome and copy/pasted the JSON from the backup and overwritten the existing JSON using&amp;nbsp;&lt;A href="https://ago-assistant.esri.com/" target="_blank" rel="noopener"&gt;https://ago-assistant.esri.com/&lt;/A&gt;.&amp;nbsp; Problem with that is you'd get a new item ID which could break other things like scripts or links you'd already established.&lt;BR /&gt;&lt;BR /&gt;I've used the script mostly to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;See what items in my ORG were changed when and have a log each day to refer back to or to restore back to&lt;/LI&gt;&lt;LI&gt;If an item really got screwed up, I would go into AGO Assistant and replace the json with the backup json and see if that fixed the item.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I go in &lt;A href="https://ago-assistant.esri.com/" target="_blank" rel="noopener"&gt;AGO Assistant&lt;/A&gt;.&amp;nbsp; I search for the item (by default it only display items you own) by name or itemID.&lt;BR /&gt;Find the item and in the dropdown choose&amp;nbsp;&lt;STRONG&gt;I want to...View an Item's JSON&lt;/STRONG&gt;&lt;BR /&gt;Replace the &lt;STRONG&gt;Data&lt;/STRONG&gt; of it's json with the .json file you have backed up on your network.&lt;BR /&gt;Hit save and then view that item in Chrome or Field Maps.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_Laue_0-1731953706533.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/119771i118F2B7B5CF75783/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_Laue_0-1731953706533.png" alt="Tom_Laue_0-1731953706533.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2024 18:15:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1559803#M62441</guid>
      <dc:creator>Tom_Laue</dc:creator>
      <dc:date>2024-11-18T18:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Hosted feature layer backups periodically</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1560170#M62458</link>
      <description>Thanks Tom, your instructions are very clear. This will help me a lot.&lt;BR /&gt;Regards&lt;BR /&gt;Hanlie&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Nov 2024 13:11:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1560170#M62458</guid>
      <dc:creator>HanliePetoors</dc:creator>
      <dc:date>2024-11-19T13:11:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to create Hosted feature layer backups periodically</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1671694#M67326</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;This code is very useful, thank you for providing it. I was wondering if you could provide insight on how it could be adjusted to add a FGDB item into a Backup folder in ArcGIS Online through a scheduled notebook, as opposed to scheduling a python script to export the backups to my C drive. If you are able to assist, I'd greatly appreciate it!&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 09 Dec 2025 17:31:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-create-hosted-feature-layer-backups/m-p/1671694#M67326</guid>
      <dc:creator>emoreno</dc:creator>
      <dc:date>2025-12-09T17:31:07Z</dc:date>
    </item>
  </channel>
</rss>

