I have the following script which I use to export online layers to File Geodatabases in a folder on my computer.
import arcgis
from arcgis.gis import GIS
from datetime import datetime
from time import strftime
import os
import itertools
# Backup Script
for (a, b) in zip(item_ids, folder_list):
folderlocation = mainfolder + "/" + b
itemid = a
print(itemid, folderlocation)
#create a backup online
dataitem = gis.content.get(itemid) #fetch the item to be backed-up
backupname = f"{dataitem.title}_Backup_"+ date_time #create a name for the backup using the existing item name
dataitem.export(backupname, itemtype, parameters=None, wait=True, tags=itemtags, snippet = itemdesc) #export the data to a file geodatabase within the user's content
#create a backup online
dataitem = gis.content.get(itemid) #fetch the item to be backed-up
backupname = f"{dataitem.title}_Backup_"+ date_time #create a name for the backup using the existing item name
dataitem.export(backupname, itemtype, parameters=None, wait=True, tags=itemtags, snippet = itemdesc) #export the data to a file geodatabase within the user's content
## Move the backup to designated folder, if not root
searchquery = f"title:{backupname} AND owner:{username}" # search query using item title and owner
searchresult = gis.content.search(backupname, item_type=itemtype) #find the backup that was just created
backupitem = gis.content.get(searchresult[0].itemid) #get the itemid of that new item
print(backupitem)
# download backup and delete online file
backupitem.download(save_path=folderlocation, file_name= backupname + ".zip")
backupitem.delete()
# extract zipped folders
zippath = folderlocation + "/"+ backupname + ".zip"
extractpath = folderlocation + "/"+ backupname
if not os.path.exists(extractpath):
os.makedirs(extractpath)
import zipfile
with zipfile.ZipFile(zippath, 'r') as zip_ref:
zip_ref.extractall(extractpath)
os.remove(zippath)
This script works fine for 3 feature layers that I have online, but not for another 4. It seems that the problem lies with the data.export part of the script, which for these 4 layers exports an empty file geodatabase. I've attached a screenshot of one of the attribute table of one of these layers to show the issue - the data schema is exported but none of the data actually within the layer.
Basically, I am just wondering what could prevent the data from being exported - I have checked the settings on the layers and can't see anything different from the ones that successfully exported.
Thank you