Skip to content

Instantly share code, notes, and snippets.

@randybondsjr
Created November 12, 2019 19:49
Show Gist options
  • Save randybondsjr/6a3697d296bcfe32787af4071c448f79 to your computer and use it in GitHub Desktop.
Save randybondsjr/6a3697d296bcfe32787af4071c448f79 to your computer and use it in GitHub Desktop.
import arcpy, datetime, os
logpath = r"d:\\scripts\\Tahoma Cemetery\\logs\\"
logfile = logpath + 'DBadmin.txt'
if arcpy.Exists(logfile):
arcpy.Delete_management(logfile)
log = open(logfile, 'a')
print >> log, "---------------------" + str(datetime.date.today()) + "---------------------"
start_time = datetime.datetime.now()
#---Database Admin Connections---
sde = r"D:\Scripts\SDE\Cemetery.sde"
arcpy.env.workspace = sde
datalist = arcpy.ListFeatureClasses() + arcpy.ListDatasets()
arcpy.ClearWorkspaceCache_management()
#Rebuild Indexes as SDE
arcpy.RebuildIndexes_management(sde,"NO_SYSTEM",datalist, "ALL")
print arcpy.GetMessages()
print >> log, "Rebuilt indexes..."
arcpy.AnalyzeDatasets_management(sde, "NO_SYSTEM", datalist, "ANALYZE_BASE", "ANALYZE_DELTA", "ANALYZE_ARCHIVE")
print arcpy.GetMessages()
print >> log, "Analyzed datasets..."
arcpy.Compress_management(sde)
end_time = datetime.datetime.now()
diff = end_time - start_time
print >> log, "process took " + str(diff)
log.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment