I have two geodatabases, one is a production sde database, the other is a backup in a local file geodatabase. The script runs as a task once a month and is very resource intensive. I am using ArcGIS for Desktop 10 SP 5.
What I would like to do is use a search and update cursor for each feature class in the database, including feature data sets; if there has been any change to the feature class; then just update the backup based on what is in the production instead of deleting it.
The example here shows how to update a feature class based on a field and changes to a field. I would like to parse and update all feature classes in gdb2 if there is a change to a feature class in gdb1. How can this script be modified to meet my needs?
import arcpy
#input feature class
fc2 = r"C:\temp\temp.gdb\fc2"
#target feature class
fc3 = r"C:\temp\temp.gdb\fc3"
#check field
checkField = "SRNumber"
#Get list of values in field from target feature class
checkValues = [r[0] for r in arcpy.da.SearchCursor (fc3, checkField)]
#Get list of fields
fields = [f.name for f in arcpy.ListFields (fc2)]
#Get index of check field
index = fields.index (checkField)
#Create insert cursor for fc3 to allow appending of rows
inCursor = arcpy.da.InsertCursor (fc3, fields)
#Create search cursor to iterate input feature class
cursor = arcpy.da.SearchCursor (fc2, fields)
#iterate
for row in cursor:
#Get value to check
checkValue = row[index]
#Check if value is in target fc
if checkValue in checkValues:
#skip if value is in target fc
continue
#Insert row otherwise
inCursor.insertRow(row)
#Clean up
del cursor
del inCursor
da
module was made available at 10.1. Withwalk
it would be simple to iterate over a GDB assuming the structures are identical.