@heatherdaw this is the full script I'm using to create a backup fgdb of a hosted feature layer in my content. It overwrites the existing backup each time. Hope that helps.
from arcgis.gis import GIS
from time import strftime
gis = GIS("home")
username = gis.properties.user.username
home_dir = os.path.abspath(os.path.join(os.sep, 'arcgis', 'home'))
# Variables
itemid = "000abc000abc000abc000abc000abc00" # AGO layer to backup
itemtype = "File Geodatabase" # export format
itemtags = "backup, fgdb" # item tags
itemdesc = strftime("This backup was generated on %m/%d/%Y.") # item description
folderlocation = "/" # export folder, / is root folder
# Check to see if a backup file geodatabase already exists
dataitem = gis.content.get(itemid) #fetch the item to be backed-up
backupname = f"{dataitem.title} Backup" #acquire backup name using the source hosted feature layer
searchquery = f"title:{backupname} AND owner:{username}" # search query using item title and owner
searchresult = gis.content.search(query=searchquery, item_type=itemtype, sort_field='uploaded', sort_order='desc') #search for existing backups
print(f'Found {len(searchresult)} existing backups')
# Update existing backup item, if it exists
if len(searchresult) >= 1:
print('Updating existing backup file...')
dataitem = gis.content.get(itemid) #fetch the item to be backed-up
backupname = f'{dataitem.title} Backup' #create a name for the backup using the existing item name
dataitem.export(backupname, itemtype, parameters=None, wait=True, tags=itemtags, snippet = itemdesc, overwrite=True) #export the data to a file geodatabase within the user's content
searchquery = f"title:{backupname} AND owner:{username}" # search query using item title and owner
searchresult = gis.content.search(query=searchquery, item_type=itemtype, sort_field='uploaded', sort_order='desc') #find the new temporary backup item that was just created
backupitem = gis.content.get(searchresult[0].itemid)
dwnldname = backupname.replace(" ","_")
backupitem.download(save_path=home_dir, file_name=dwnldname + '.zip')
searchquery = f"title:{backupname} AND owner:{username}" # search query using item title and owner
searchresult = gis.content.search(query=searchquery, item_type=itemtype, sort_field='uploaded', sort_order='asc') #search for the previous backup
oldbackup = gis.content.get(searchresult[0].itemid)
itemprops = {"snippet":f"{itemdesc}","description":f"{itemdesc}"}
oldbackup.update(item_properties=itemprops, data = os.path.join(home_dir, dwnldname, '.zip'))
backupitem.delete(dry_run=False) #Can change dry_run to True for testing, won't remove duplicate backups
#Create a new backup if no previous backup exists
else:
print('Creating new backup...')
dataitem = gis.content.get(itemid) #fetch the item to be backed-up
backupname = f'{dataitem.title} Backup' #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
if folderlocation != "/":
print('Moving backup to designated folder...')
backupitem.move(folder=folderlocation) #move the item to the correct user folder, if user chose somewhere other than the default root
-Aaron